我加了幾個字段(Email
,Forename
,Surname
等)到AspNetUsers
表,但我想知道是否有可能修改裏面的標準的MVC模板的登錄Visual Studio 2013改爲使用新的Email
字段。MVC登錄使用不同的領域,防止重複
我已經改變了一切,據我所見,請看下面。
LoginViewModel
public class LoginViewModel
{
[Required]
[Display(Name = "Email Address")]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
的AccountController
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.Email, model.Password);
if (user != null)
{
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", "Invalid Email or password.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
對於一些未知的原因,儘管註冊過程中節省在正確的字段中的值,我不能與用戶使用的登錄電子郵件地址,除非用戶註冊後打開AspNetUsers表並交換電子郵件和用戶名數據。
請問我錯過了什麼?
還有可能在註冊之前檢查現有的電子郵件地址以確保沒有可能的重複?
任何幫助,將不勝感激:-)