Luca Romagnoli
Luca Romagnoli

Reputation: 12465

Get the username in Forms 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?

Upvotes: 34

Views: 48363

Answers (3)

Chris F Carroll
Chris F Carroll

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

Matt
Matt

Reputation: 1374

To get the UserName of the authenticated user:

HttpContext.Current.User.Identity.Name;

Upvotes: 64

MAW74656
MAW74656

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

Related Questions