Reputation: 12465
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?
Upvotes: 34
Views: 48363
Reputation: 12370
It may depend on when in the lifecycle you are asking.
If you handle BeginRequest()
then there will not yet be any authentication information. Whereas if you handle EndRequest()
there will.
Upvotes: 0
Reputation: 1374
To get the UserName of the authenticated user:
HttpContext.Current.User.Identity.Name;
Upvotes: 64
Reputation: 3539
That's exactly how I do it, I think there might be something wrong with your setup? For example, are you actually logged into the site while your debugging? If not, you need to in order to get a value.
Upvotes: 1