本文介绍了使用用户名,而不是电子邮件在Asp.net mvc5身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我用Visual Studio创建2013前preSS对网络的新应用程序,并使用个人账户身份验证和我打的注册按钮,我注意到,它实现的,而不是用户名电子邮件和同样是在LoginViewModel因为它使用电子邮件来登录用户名的替代。我怎样才能改变这种无故障使用而不是默认的邮件用户名?此外,我想知道如何转换默认的GUID这是一个字符串类型'ID'(整型)。

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).

推荐答案

在接受答案的链接的问题descibes如何使用,而不是用户名通过电子邮件,OP想要的用户名,而不是电子邮件这就是我在标识2.0找在MVC项目。

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.........

添加用户名到RegisterViewModel并把它添加到寄存器视图。

Add UserName to the RegisterViewModel and add it to the register view.

<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>

在注册后操作上的AccountController设置用户名的视图模型的用户名和电子邮件到视图模型的电子邮件。

In the Register Post Action on the AccountController set the UserName to the ViewModel's UserName and the Email to the ViewModel's Email.

var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };

这篇关于使用用户名,而不是电子邮件在Asp.net mvc5身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:17
查看更多