For some (obscure) reason my MVC 4 application returns a guid when I run:
var name = User.Identity.Name;
I have also tested this in a brand new MVC 4 application and this is new behavior to me. When I look up the documentation on IIdentity it states (as I remembered) that Identity.Name should
Gets the name of the current user.
Why is it returning a guid in my case?
From the web.config
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
More relevant information: The application is also deployed on another machine, talking to the same database. We use the value of "User.Identity.Name" in that database and when it's not there for a user (new user) we add a new user with that guid.
Now, what is strange: when you switch applications (from localhost to the one deployed on T) you need to log in again. The User.Identity.Name will then be set to a new guid.
(with the starter default application we don't talk to the DB of course, but the same thing happens; User.Identity.Name returns a guid)
User-id definitionThe user name, or username, by which a person is identified to a computer system or network. A user commonly must enter both a user ID and a password as an authentication mechanism during the logon process.
It just holds the username of the user that is currently logged in. After login successful authentication, the username is automatically stored by login authentication system to "HttpContext.Current.User.Identity.Name" property.
It is most likely stored in Managed Passwords: Click Start > Run. Enter "control userpasswords2"
You'll need to find the generic principal object which corresponds to the current user.
using System.Security.Principal;
...
GenericPrincipal genericPrincipal = GetGenericPrincipal();
GenericIdentity principalIdentity = (GenericIdentity)genericPrincipal.Identity;
string fullName = principalIdentity.Name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With