title: FormsAuthentication Cookie Not Saving
body: <p>I have two login pages. One for admin users and one for customers.</p>
  
  <p>They both execute the below code (after authorisation) to add a cookie to the <code>Response</code>. The two pages then redirect to the URL provided (I don't do the redirect here as I do some extra checks on admin)</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static string SetAuthCookie&lt;T&gt;
      (this HttpResponse responseBase, string name, bool rememberMe, T userData)
  {
      /// In order to pickup the settings from config, we create a default cookie 
      /// and use its values to create a new one.
      var cookie = FormsAuthentication.GetAuthCookie(name, true);
      var ticket = FormsAuthentication.Decrypt(cookie.Value);
  
      var newTicket = new FormsAuthenticationTicket(
          ticket.Version, 
          ticket.Name, 
          ticket.IssueDate, 
          ticket.Expiration,
          true,
          Newtonsoft.Json.JsonConvert.SerializeObject(userData), 
          ticket.CookiePath
          );
  
      var encTicket = FormsAuthentication.Encrypt(newTicket);
  
      /// Use existing cookie. Could create new one but would have to copy settings over...
      cookie.Expires = (rememberMe ? DateTime.Now.AddDays(62) : DateTime.MinValue);
  
      cookie.Value = encTicket;
  
      responseBase.Cookies.Set(cookie);
  
      return FormsAuthentication.GetRedirectUrl(name, true /*This Is Ignored*/);
  }
  </code></pre>
  
  <p><strong>Admin</strong><br>
  Now the admin does as it's told. Adds the cookie and redirects to an admin welcome screen.</p>
  
  <p><strong>Customer</strong><br>
  The customer login area just isn't doing the same (see below screengrab). </p>
  
  <ol>
  <li>It posts (as you can see it receives the request to save the cookie) </li>
  <li>It redirects</li>
  <li>But, oh no, the next request has no cookie</li>
  <li>The system can't see the user is authenticated</li>
  <li>Back to the login screen we go</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/tivEk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tivEk.jpg" alt="The process of redirects"></a></p>
  
  <p>I thought that the problem may be a local browser.<br>
  Nope, tried: different browsers, using private/incognito.</p>
  
  <p>I thought it might be the setting of the cookie.<br>
  How can it be? They both use the same code.</p>
  
  <p>Maybe <code>web.config</code> (in their respected directories)?<br>
  Nope, just <code>&lt;authorization&gt;</code> rules</p>
  
  <p>Maybe a problem with the cookie?<br>
  Nope, looks fine. Same domain, HTTPS. all fine</p>
  
  <p>Something to do with <code>RememberMe</code>?<br>
  Nope, tried both with and without</p>