ASP.NET Core 3.1 无法取消保护消息。状态在调试器中运行

2024-02-24

我已使用默认模板从 VS 2022 创建了 ASP.NET Core 3.1 Web 应用程序,并选择 Microsoft Identity 来使用 Azure AD 身份验证。向导在我的 Azure AD 租户中生成了应用程序注册,一切看起来都很好(回复 URL 等)

当我从调试器运行新生成的 Web 应用程序时,系统会提示我输入 Azure AD 凭据,然后重定向回我的应用程序并出现以下异常:

Exception: Unable to unprotect the message.State.

Unknown location
Exception: An error was encountered while handling the remote login.

Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()

请注意,我没有添加或修改任何代码。它是 100% 由 VS2022 模板生成的。


  • 这个错误“异常:无法取消对消息的保护。状态”,通常发生在您有多个OIDC中间件。如果您有多个 OIDC,请检查是否需要为每个 OIDC 设置唯一的回调路径。
  • 将每个 OIDC 提供商的身份验证方案命名为oidc-demo and oidc-master.
  • The 状态参数返回时未正​​确解密,可能是因为您的 OIDC 提供商之一正在尝试解密/取消保护另一条消息的状态。
  • 尝试添加数据保护提供商根据github https://github.com/dotnet/aspnetcore/issues/13316#issuecomment-524946933讨论。

请检查以下内容links用于数据保护:

配置 ASP.NET Core 数据保护 |微软文档 https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-6.0

c# - Kubernetes 中的 Azure AD 身份验证无法取消对消息的保护。状态 - 代码日志 https://stackoverflow.com/questions/60302735/azure-ad-authentication-in-kubernetes-unable-to-unprotect-the-message-state

  • 确保重定向URI应该是您自己的控制器中的操作方法,如下所示:

            https://localhost:44381/test/callback 
    
  • 检查 UnProtect 方法收到消息时按照本文中讨论的方式解密link https://stackoverflow.com/questions/68925956/the-default-requested-state-parameter-value-length-is-not-supported-for-my-exter.

如需了解更多详情,请refer以下链接:

asp.net core - 重定向到IdentityServer4中的客户端时出现错误代码500“无法取消保护消息。状态” - Thinbug https://stackoverflow.com/questions/62791068/error-code-500-unable-to-unprotect-the-message-state-when-redirecting-to-clien.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ASP.NET Core 3.1 无法取消保护消息。状态在调试器中运行 的相关文章

随机推荐