How to use email as httpcontext.User.Identity.name

2019-09-11 14:21发布

问题:

I'm creating a new asp.net MVC3 app in which in user table I do not wish to have user name but only user id (long) and email (string). What I would like to understand is normally when I use membership provider with normal db structure, I get the username value in db as the User.Identity.Name.

Could someone please tell me what changes I need to do as I will not have any username in my db to ensure that my email address becomes my User.Identity.Name

Thanks Arnab

Answer: found out... its FormsAuthentication.SetAuthCookie that decides which value goes to user.identity.name

回答1:

The value User.Identity.Name typically comes from the "username" you provide the login form. This is stored by the LogOnModel class within the AccountModels model.

To set your email address as User.Identity.Name, you must provide your email address in the username field of the login form. Then use your membership provider to authenticate the user based on the provided email address.



回答2:

found out... its FormsAuthentication.SetAuthCookie that decides which value goes to user.identity.name