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 ?
Asked
Active
Viewed 1,197 times
3 Answers
2
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.

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
2
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);

Juraj Suchár
- 1,107
- 6
- 25
-
It was the simple issue , thanks Mr Juraj and thank you all for your answers !! – ucef Jun 01 '12 at 15:19
0
As Darin said, its by design.
In your forms authentication cookie creation method, just save your UserID in the Name property

Jason Kulatunga
- 5,814
- 1
- 26
- 50