title: C#/ASP.NET Selenium WebDriver - Re-using Cookies
body: <p>I want to:</p>
  
  <ul>
  <li>Login to a website</li>
  <li>Save Cookies </li>
  <li>Give user a choice to do A, B or C </li>
  <li>A,B and C all require being logged in. </li>
  <li>Each will open a FirefoxDriver and do their own thing</li>
  </ul>
  
  <p>What i want to do, is login <strong>ONCE</strong>, save the cookies from that, and add them to any other FirefoxDriver i want to open.</p>
  
  <p>Right now I'm trying to save the cookies in</p>
  
  <pre><code>public ReadOnlyCollection&lt;Cookie&gt; Cookies { get; set; }
  </code></pre>
  
  <p>which is the result of</p>
  
  <pre><code>WebDriver.Manage().Cookies.AllCookies;
  </code></pre>
  
  <p>Assuming login worked and cookies were saving in the above, I have this:</p>
  
  <pre><code>        WebDriver = new FirefoxDriver();
          WebDriver.Navigate().GoToUrl("http://www.example.com");
  
          if (cookies != null)
          {
              var s = WebDriver.Manage().Cookies;  //Logged out cookies
              WebDriver.Manage().Cookies.DeleteAllCookies(); //Delete all of them
              var sd = WebDriver.Manage().Cookies; //Make sure theyre deleted
              foreach (var cookie in cookies)
              {
                  WebDriver.Manage().Cookies.AddCookie(cookie);
              }
              var ss = WebDriver.Manage().Cookies; 
              WebDriver.Navigate().GoToUrl("http://example.com/requiresloginpage");
          }
  </code></pre>
  
  <p>The problem is, howevering over "ss" in this case, gives this exception error</p>
  
  <pre><code>AllCookies = 'ss.AllCookies' threw an exception of type
  'OpenQA.Selenium.WebDriverException'
  base {System.Exception} = {"Unexpected problem getting cookies"}
  InnerException = {"Cookie name cannot be null or empty string\r\nParameter name: name"}
  </code></pre>
  
  <p>I'm passing 8 cookies (total number when youre logged in) - and all of them seem set and ok. Not sure what I'm doing wrong</p>