Whenever I create a new application with visual studio 2013 express for web and using the individual accounts authentication and i hit the register button I notice that it implements 'Email' instead of 'Username' and the same is in the LoginViewModel as it uses Email to Sign in instead of Username. How can i change this to use Username instead of the default Email without trouble? Also i would like to know how to convert the default 'guid' that is a string type to 'id' (integer type).
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- MVC-Routing,Why i can not ignore defaults,The matc
- How to know full paths to DLL's from .csproj f
- How to store image outside of the website's ro
- Importing NuGet references through a local project
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- How to show location of errors, references to memb
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
The linked question in the accepted answer descibes how to use Email instead of UserName, OP wanted the UserName instead of email which is what I was looking for in Identity 2.0 in an MVC project.
In case anyone else gets here from a google search it is actually very easy to do this. If you look at the register post action it is simply setting the UserName to the Email address. So.........
Add UserName to the RegisterViewModel and add it to the register view.
In the Register Post Action on the AccountController set the UserName to the ViewModel's UserName and the Email to the ViewModel's Email.
Please look into this thread
Thread Details :
Assumptions:
Remove
EmailAddress
annotation and define Display text in the defaultLoginViewModel
:As user can enter either
Username
orEmail
, so we will make @ character for validation criteria. Here is the flow to be implemented:Email
validation else applyUsername
format validation.Email
, first we need to getUsername
. As it is considered thatUsername
is unique so we can get it withuserManager.FindByEmailAsync
method.Use
Username
forSignIn
verification.No special need to change in View. Run the application and test login with Email or Username.
Note: Keep in mind this tutorial follows MVC .Net Identity default structure.
In order to make email as non unique:
Configure below in IdentityConfig
You can also use username and/or password like this