ucef
ucef

Reputation: 557

the value of "User.Identity.Name" on asp.net mvc 3

i work on web app using asp.net mvc 3 , the problem is with the variable "User.Identity.Name" taht return name and not UserId . have you already this problem ?

Upvotes: 0

Views: 1201

Answers (3)

Juraj Suchár
Juraj Suchár

Reputation: 1117

User.Identity.Name property contains the string, that was passed to FormsAuthentication.SetAuthCookie(thisString) during authentication.

If you want this property to contain an userId, change the authentication code to

FormsAuthentication.SetAuthCookie(userId);

Upvotes: 2

Jason Kulatunga
Jason Kulatunga

Reputation: 5893

As Darin said, its by design.

In your forms authentication cookie creation method, just save your UserID in the Name property

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

have you already this problem ?

That's not a problem. It is by design. Inside the forms authentication cookie only the username is stored. You could have an index on your database on the username column and efficiently retrieve the user details given this unique username.

Upvotes: 2

Related Questions