ASP.NET Identity Provider SignInManager Keeps Retu

2019-03-11 23:41发布

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.Password, model.RememberMe, shouldLockout: false);

keeps returning Failure. So I started debugging, By using:

UserManager.FindByEmail(model.Email);

This returns a valid UserID for my user trying to log in. Then I used:

SignInManager.UserManager.CheckPassword(UserIDObtainedFromFind, model.Password);

And this returns true, which means that the password I provide is valid....

Sign In failure

Any ideas on how I can trace, of debug the SignInManager.PasswordSignInAsync method to see where it fails?

9条回答
smile是对你的礼貌
2楼-- · 2019-03-12 00:15

In case none of the above is your cause for the problem (in my case the problem was a copy-paste bug in my own implementation of IUserStore) and to answer your question "Any ideas on how I can trace, or debug the SignInManager.PasswordSignInAsync method to see where it fails?", one way to debug it would be to copy the contents of the method SignInManager.PasswordSignInAsync into your own derived class (ApplicationSignInManager).

You may find the source code in here or here if you're using MVC5 and lower.

查看更多
做自己的国王
3楼-- · 2019-03-12 00:19

Maybe my experience can help somebody. In my case, the problem was that I changed my computer, and in my new Windows 10, IIS feature was installed but not ASP.NET feature.

enter image description here

查看更多
欢心
4楼-- · 2019-03-12 00:23

It's Work for me

ApplicationUser signedUser = UserManager.FindByEmail(model.Email);
var result = await SignInManager.PasswordSignInAsync(signedUser.UserName, model.Password, model.RememberMe, shouldLockout: false);
查看更多
啃猪蹄的小仙女
5楼-- · 2019-03-12 00:29
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.

查看更多
时光不老,我们不散
6楼-- · 2019-03-12 00:35

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'
查看更多
放我归山
7楼-- · 2019-03-12 00:37

If username != email:

ApplicationUser signedUser = UserManager.FindByEmail(model.Email);
var result = await SignInManager.PasswordSignInAsync(signedUser.UserName, model.Password, model.RememberMe, shouldLockout: false);
查看更多
登录 后发表回答