我目前正在实现登录ASP.NET MVC项目的功能。我正在尝试尽可能多地使用所提供的方法。
目前,我已经在数据库中建立了一个名为User的表,该表存储了所有用户名,密码和有关用户的其他详细信息。
我的LoginViewModel:
public class LoginViewModel
{
public User User { get; set; }
}
AccountController(通常是默认值,我只更改了PasswordSignInAsync方法的变量)
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
return View(model);
}
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.User.Username, model.User.Password, false , shouldLockout: false);
为什么此行总是返回失败?
这是我第一次尝试添加登录功能,因此将不胜感激。:)
添加
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
在方法public void ConfigureAuth(IAppBuilder app)
中App_Start\Startup.Auth.cs