简体   繁体   English

ASP.NET Core 登录失败,如何找出登录失败的原因?

[英]How to find out the reason for failed signing in, when ASP.NET Core fails to sign in?

I'm using ASP.NET Core Identity to manage users.我正在使用 ASP.NET Core Identity 来管理用户。 And I get this response when I'm trying to sign-in a user:当我尝试登录用户时,我收到此响应:

{
    type: "Error",
    message: "Not logged in",
    data: {
        succeeded: false,
        isLockedOut: false,
        isNotAllowed: false,
        requiresTwoFactor: false
    }
}

As you can see, user is not logged in, and no other reason is true .如您所见,用户未登录,并且没有其他原因为true

What should I do now to find out "why" user has not logged in?我现在应该怎么做才能找出“为什么”用户没有登录? How to find the error here?如何找到这里的错误?

The method I'm using is PasswordSignInAsync and the result it returns is SignInResult and it does not have a field for the error description.我使用的方法是PasswordSignInAsync并且它返回的结果是SignInResult并且它没有用于错误描述的字段。

The method I'm using is PasswordSignInAsync and the result it returns is SignInResult and it does not have a field for the error description.我使用的方法是 PasswordSignInAsync 并且它返回的结果是 SignInResult 并且它没有用于错误描述的字段。

To troubleshoot the issue, you can refer to the following code snippet to check if user is existing/registered, then check if the given password is valid for the specified user.要解决此问题,您可以参考以下代码片段来检查用户是否存在/注册,然后检查给定的密码对指定用户是否有效。

//check if user is existing 
var user = await _userManager.FindByEmailAsync(Input.Email); //or .FindByNameAsync(username_here)


//check if pwd is valid
var pwd_is_valid = _userManager.CheckPasswordAsync(user, Input.Password);

And, you can try to debug your code and check if any useful logs are written to output window.而且,您可以尝试调试代码并检查是否有任何有用的日志写入输出窗口。

在此处输入图片说明

Besides, you can try to register a new user and login with that new user's account to check if it can work well.此外,您可以尝试注册一个新用户并使用该新用户的帐户登录以检查它是否可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在ASP.NET Core Identity中注销用户 - How to sign out a user in ASP.NET Core Identity 如何在 ASP.NET Core Identity 中注销其他用户 - How to sign out other user in ASP.NET Core Identity Asp.Net Core WebApi 的身份验证失败并显示“Unprotect ticket failed” - Authentication fails with "Unprotect ticket failed" for Asp.Net Core WebApi 运行 dotnet publish -c Release -o out 时,在 ASP.NET Core 项目中构建 Dockerfile 失败 - Building Dockerfile in ASP.NET Core project fails when running dotnet publish -c Release -o out 如何获取 ASP.NET Core 应用程序关闭的原因? - How to get reason for ASP.NET Core application shutting down? Asp.Net Core-无故返回500 - Asp.Net Core - Returns 500 for no reason 当在 Blazor 应用程序中使用 Azure Active Directory 时如何在 asp net core 3.1 中自定义注销页面 - How to customize sign out page in asp net core 3.1 when Azure Active Directory used in a Blazor application 当我在 asp.net core mvc 中未经授权时,如何始终返回登录/登录视图? - How to always return login/sign in view when I'm unauthorized in asp.net core mvc? 发布时从另一个ASP.NET Core 2项目引用ASP.NET Core 2项目失败 - Referencing ASP.NET Core 2 project from another ASP.NET Core 2 project fails when publishing ASP.NET Core 1.1在发布时无法运行 - ASP.NET Core 1.1 fails to run when published
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM