随缘 我不喜欢太复杂的东西

导航

MVC5 Identity 用用户名登录而不用电子邮件

1、修改AccountViewModels
·修改RegisterViewModel
public class RegisterViewModel
{
    [Required]
    [Display(Name = "用户名")]
    public string UserName { get; set; }
    .......
}

·修改LoginViewModel

public class LoginViewModel
{
    [Required]
    [Display(Name = "用户名")]
    public string UserName { get; set; }
    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "密码")]
    public string Password { get; set; }
    [Display(Name = "记住我?")]
    public bool RememberMe { get; set; }
}
2、修改AccountController
修改注册页面控制器
var user = new ApplicationUser { UserName = model.UserName, Email = model.Email};
修改登录页面控制器
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);

3、修改页面

完成


posted on 2015-08-24 21:39  随缘py  阅读(800)  评论(3编辑  收藏  举报