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、修改页面
完成