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

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

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

I am currently implementing the ability to login on my ASP.NET MVC project. I am trying to use as much of the provided methods as I can.

Currently, I have set up a table in my database known as User, which stores all the usernames, passwords and other details regarding the users.

My LoginViewModel:

public class LoginViewModel
{
    public User User { get; set; }
}

The AccountController (which is mostly the default, I have only changed the variables of the PasswordSignInAsync method)

[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);

Why does this line always return a Failure?

It's my first time trying to add the Login ability, so any help would be greatly appreciated. :)

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

Add

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

To method public void ConfigureAuth(IAppBuilder app) in App_Start\Startup.Auth.cs