title: HttpContext.Current.User.Identity.Name is always null
body: <p>I know this question has been asked before but each question has a different scenario to what I have or I am missing the obvious.</p>
  
  <p>So I have implemented SSO architecture, so the user click on log in and redirected to identity server and log in there and get redirected back to the application.</p>
  
  <p>in one of my application I want to use the <code>HttpContext.Current.User.Identity.Name</code> in my <code>membershipprovider</code>, but it is always empty. so I found out that I need create a cookie and set it up properly to get the <code>HttpContext.Current.User.Identity.Name</code> form wherever I want.</p>
  
  <p>My code look like this:</p>
  
  <p>After the user is redirected from the Identity server to a login control:</p>
  
  <pre><code>if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
  {
      FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                  HttpContext.Current.Session["username"].ToString(),
                  DateTime.Now, DateTime.Now.AddMinutes(30), true, String.Empty, 
                  FormsAuthentication.FormsCookiePath);
      string encryptedCookie = FormsAuthentication.Encrypt(ticket);
      HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
                          encryptedCookie);
      cookie.Expires = DateTime.Now.AddMinutes(30);
      Response.Cookies.Add(cookie);
      FormsAuthentication.RedirectFromLoginPage("/my-profile", true);
  }
  </code></pre>
  
  <p>My web config file looks like this:</p>
  
  <pre><code> &lt;authentication mode="Forms"&gt;
       &lt;forms domain="http://localhost:8081" name="yourAuthCookie" loginUrl="login.aspx" 
        protection="All" path="/" /&gt;
   &lt;/authentication&gt;
   &lt;authorization&gt;
        &lt;allow users="?" /&gt;
   &lt;/authorization&gt;
  </code></pre>
  
  <p>after the user is redirected to the my profile page the <code>System.Web.HttpContext.Current.User.Identity.IsAuthenticated</code> is true and the <code>AuthinticationType</code> = Cookies. but the Name is empty.</p>
  
  <p>I am using asp.net webforms.</p>
  
  <p>UPDATE: I have tried to set the <code>HttpContext.Current.User</code> it is set properly but when the page load or redirected it goes back to null empty.</p>
  
  <pre><code>  if (ticket != null &amp;&amp; !ticket.Expired)
  {
        var roles = ticket.UserData.Split(',');
       System.Web.HttpContext.Current.User = new   System.Security.Principal.GenericPrincipal(new FormsIdentity(ticket), roles);
    }
  </code></pre>
  
  <p>any help will be much appreciated.</p>