Get the username in Forms authentication

Luca Romagnoli picture Luca Romagnoli · Feb 10, 2011 · Viewed 44.8k times · Source

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?

Answer

Matt picture Matt · Feb 10, 2011

To get the UserName of the authenticated user:

HttpContext.Current.User.Identity.Name;