title: c# - CookieException during CookieContainer.Add, part of the cookie is invalid
body: <p>I have a Windows Phone 8 application that needs to speak with a server. The server sets a cookie to my <code>HttpClient</code>'s client handler when I call the login service on the server (which is located under sub-directory "/authentication"). Then I take this <code>Cookie</code> and store it in the <code>IsolatedStorageSettings</code>. When I close and re-open my application, thus re-instantiating my <code>HttpClient</code>, I want to get the <code>Cookie</code> from <code>IsolatedStorageSettings</code> and set it to my client handler manually. However, I get a <code>CookieException</code> with the message: "The 'Domain'='mobile.some-domain.com' part of the cookie is invalid."</p>
  
  <p>The code I wrote for this as follows:</p>
  
  <pre><code>public static void saveCookies()
  {
      IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
      var cookies = handler.CookieContainer.GetCookies(new Uri(ROOT + "/authentication"));
      settings["sessionCookie"] = cookies["JSESSIONID"];
      settings.Save();
  }
  
  public static bool checkCookies()
  {
      IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
      if (settings.Contains("sessionCookie"))
      {
          Cookie c = settings["sessionCookie"] as Cookie;
          Uri uri = new Uri(ROOT + "/authentication");
          handler.CookieContainer.Add(uri, c);
          return true;
      }
      return false;
  }
  </code></pre>
  
  <p>ROOT is "<a href="https://mobile.some-domain.com/ERSMobileApps/services" rel="nofollow">https://mobile.some-domain.com/ERSMobileApps/services</a>" and the type of handler is <code>HttpClientHandler</code>.</p>
  
  <p>I'm dealing with cookies for the first time, so any help/comment on this would be appreciated. Thanks in advance.</p>