Warm tip: This article is reproduced from serverfault.com, please click

c#-等待SignInManager.PasswordSignInAsync()总是导致我的ASP.NET MVC项目失败

(c# - await SignInManager.PasswordSignInAsync() always results in a failure in my ASP.NET MVC project)

发布于 2015-07-30 22:14:20

我目前正在实现登录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);

为什么此行总是返回失败?

这是我第一次尝试添加登录功能,因此将不胜感激。:)

Questioner
fuzzi
Viewed
0
30 2016-07-27 21:13:56

添加

app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

在方法public void ConfigureAuth(IAppBuilder app)App_Start\Startup.Auth.cs