2

I am trying to retrieve the current user in my web application that uses ASP.NET Forms authentication. However, System.Security.Principal.WindowsIdentity.GetCurrent().Name returns domain\windowsUser, NOT the username that was used in the FormsAuthentication.RedirectFromLoginPage method. I am using Forms authentication in my config file:

<authentication mode="Forms">
      <forms loginUrl="Views/Login.aspx" name=".ASPXFORMSAUTH" timeout="1" cookieless="UseUri">
      </forms>
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>

I am also trying to follow Microsoft's walk through and retrieve the Authentication ticket using the following snippet:

    if (Request.IsAuthenticated)
    {
         var ident = User.Identity as FormsIdentity;
        if (ident != null)
        {

            FormsAuthenticationTicket ticket = ident.Ticket;
            var name = ticket.Name;
        }
    }

However, ident is always null because it's WindowsIdentity not FormsIdentity. What's wrong here? Thank you!

laconicdev
  • 6,360
  • 11
  • 63
  • 89

1 Answers1

2

Use User.Identity.Name to get the user name.

Windows authentication does not use the FormsAuthenticationTicket.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445