ASP.Net UserName to Email

2019-01-06 17:12发布

I am working with the new ASP.NET Identity (RTM) and I was wondering how would I go on about changing registering and login from being a UserName to an Email.

The idea is that I want my users to sign up using their e-mail and a password (e-mail can also be acquired using external login) and they set-up a display name/username on top.

I've looked at IdentityUser and I can see that UserName is there, however since that is packed in ASP.Net Identity that can not be changed.

I know I could use 'UserName' as a e-mail, with a custom validator and then have an extra attribute for ApplicationUser called DisplayName but that is more of a hack than a solution.

I hope my question is clear. Thanks in advance.

7条回答
ゆ 、 Hurt°
2楼-- · 2019-01-06 17:57

While working on a similar problem, I found the easiest solution is simply to label the Username input as "Email" and then manually set the Membership email during onCreating.

protected void RegisterUser_CreatingUser(object sender, LoginCancelEventArgs e){
    RegisterUser.Email = RegisterUser.UserName;            
}
查看更多
登录 后发表回答