ibn*_*mza 34 asp.net asp.net-mvc visual-studio
每当我使用visual studio 2013 express为web创建一个新应用程序并使用个人帐户身份验证并点击注册按钮时,我注意到它实现了"电子邮件"而不是"用户名",并且在LoginViewModel中也是如此,因为它使用Email来登录而不是用户名.如何将此更改为使用用户名而不是默认电子邮件?另外我想知道如何将字符串类型的默认'guid'转换为'id'(整数类型).
Hoo*_*ody 42
接受的答案中的链接问题描述了如何使用Email而不是UserName,OP想要UserName而不是电子邮件,这是我在MVC项目中的Identity 2.0中寻找的.
如果其他人从谷歌搜索到这里,实际上很容易做到这一点.如果您查看注册后发布操作,只需将UserName设置为电子邮件地址即可.所以.........
将UserName添加到RegisterViewModel并将其添加到寄存器视图.
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control", @placeholder = "Username or email" })
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
在AccountController上的Register Post Action中,将UserName设置为ViewModel的UserName,将Email设置为ViewModel的Email.
var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };
Run Code Online (Sandbox Code Playgroud)
小智 22
为了使电子邮件成为非唯一的:
在IdentityConfig中配置如下
manager.UserValidator = new UserValidator<ApplicationUser>(manager)
{
AllowOnlyAlphanumericUserNames = false,
RequireUniqueEmail = false
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31444 次 |
| 最近记录: |