User.Identity.Name returns guid

For some (unclear) reason, my MVC 4 application returns a control message at startup:

var name = User.Identity.Name; 

I also tested this in a new MVC 4 application, and this is a new behavior for me. When I look at the IIdentity documentation, it states (as I recall) that Identity.Name should

Returns the name of the current user.

Why does it return guid in my case?

From web.config

 <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" /> </authentication> 

Additional Information: The application is also deployed to another machine, talking to the same database. We use the value "User.Identity.Name" in this database, and when not for the user (new user), we add a new user with this director.

Now, what is strange: when switching applications (from the local host to one deployed to T), you need to log in again. Then the name User.Identity.Name will be set to the new guid.

(with the default starter application we do not talk to the database, of course, but the same thing happens: User.Identity.Name returns guid)

+7
c # asp.net-mvc asp.net-mvc-4
source share
1 answer

You will need to find a common main object that matches the current user.

 using System.Security.Principal; ... GenericPrincipal genericPrincipal = GetGenericPrincipal(); GenericIdentity principalIdentity = (GenericIdentity)genericPrincipal.Identity; string fullName = principalIdentity.Name; 
+1
source share

All Articles