ASP.NET Identity Provider SignInManager Keeps Returning Failure

后端 未结 10 1658
天涯浪人
天涯浪人 2021-01-31 15:52

I have an issue with the standard ASP Identity provider for MVC5. As soon as I log in the method:

await SignInManager.PasswordSignInAsync(model.Email, model.Pass         


        
相关标签:
10条回答
  • 2021-01-31 16:08

    It's Work for me

    ApplicationUser signedUser = UserManager.FindByEmail(model.Email);
    var result = await SignInManager.PasswordSignInAsync(signedUser.UserName, model.Password, model.RememberMe, shouldLockout: false);
    
    0 讨论(0)
  • 2021-01-31 16:12

    For me, I found it helpful to use SQL Profiler to see the query that PasswordSignInAsync was calling. In my case - I noticed it was trying to find a user with a Discriminator set to "UserContext". This of course wasn't working for me because I upgraded from ASP.NET Membership Services and this Discriminator was set to User. Since the new code uses Entity Framework, it appears this value is derived from the class you use for your user. A quick update statement fixed the issue.

    UPDATE AspNetUsers SET Discriminator = 'UserContext' WHERE Discriminator = 'User'
    
    0 讨论(0)
  • 2021-01-31 16:17
    ApplicationUser signedUser = UserManager.FindByEmail(model.Email);
    var result = await SignInManager.PasswordSignInAsync(signedUser.UserName, 
    model.Password, model.RememberMe, shouldLockout: false);
    

    This worked for me becouse my username was not equal my email. Your email and username should be the same.

    0 讨论(0)
  • 2021-01-31 16:26

    In your startup check:

    options.SignIn.RequireConfirmedEmail = false;
    options.SignIn.RequireConfirmedPhoneNumber = false;
    

    If these are set to true, you need to confirm the email or phone number before you can login.

    0 讨论(0)
  • 2021-01-31 16:27

    SignInManager.PasswordSignIn works off of user name, you should double check that the user name is the same as the email you are passing in.

    0 讨论(0)
  • 2021-01-31 16:28

    If username != email:

    ApplicationUser signedUser = UserManager.FindByEmail(model.Email);
    var result = await SignInManager.PasswordSignInAsync(signedUser.UserName, model.Password, model.RememberMe, shouldLockout: false);
    
    0 讨论(0)
提交回复
热议问题