C# – Get the username in Forms authentication

asp.netcforms-authenticationwindows-authentication

I'm using Forms authentication.

In Windows Authentication for get the user name of the PC i use: User.Identity.Name

I need this information also in Forms authentication but User.Identity.Name doesn't work.

How can I get the User.Identity.Name without using Windows authentication?

Best Answer

To get the UserName of the authenticated user:

HttpContext.Current.User.Identity.Name;