c# - OpenIdConnectAuthenticationHandler : message. 状态为 null 或为空。连接到 Azure Active Directory 时

标签 c# azure asp.net-core asp.net-core-mvc azure-active-directory

我尝试使用我的应用程序连接到 Azure Active Directory,但收到此错误: 处理请求时发生未处理的异常。

Exception: OpenIdConnectAuthenticationHandler: message.State is null or empty. Unknown location

AggregateException: Unhandled remote failure. Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.d__5.MoveNext()

我的 appsettings.json 文件如下所示:

"AzureAd": {
    "ClientId": "<Application ID value from Azure Portal>",
    "AadInstance": "https://login.microsoftonline.com/{0}",
    "TenantId": "<tenant>.onmicrosoft.com",
    "AuthCallback": "/"
  }

和 Startup.cs 中

  app.UseCookieAuthentication();

  app.UseIdentity();
  app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
  {
       ClientId = Configuration["AzureAd:ClientId"],
       Authority = string.Format(Configuration["AzureAd:AadInstance"], Configuration["AzureAd:TenantId"]),
       CallbackPath = Configuration["AzureAd:AuthCallback"]
  });

我在项目中启用了 ssl,并添加了 Visual Studio 提供的 URL 作为回复 URL。

以前,当我配置了错误的 URL 时,它会将我引导至 Microsoft 登录站点,提示该 URL 与任何已注册的 URL 都不匹配,所以我知道它至少达到了这一点。

我还应该说我正在关注 this post ,但使用新门户。我无法访问经典门户。

如何解决此错误?

感谢您的帮助。

最佳答案

如果有人遇到此问题,请向 OnMessageReceived 添加事件处理程序以调试请求。不知何故,我偶然将redirect_url设置为/signin-oidc,并且该路径上的GET将具有空上下文。属性当然会导致此特定错误

关于c# - OpenIdConnectAuthenticationHandler : message. 状态为 null 或为空。连接到 Azure Active Directory 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41152266/

相关文章:

c# - 如何将路径添加到 DLL 搜索顺序

azure - App Insight 不可用,始终显示应用程序离线或 SDK 较旧

c# - 客户可以在生产后更改环境IsDevelopment

c# - 如何在 CultureInfo(c#) 中显示尼日利亚奈拉符号

c# - ASP.NET Core JWT 将角色声明映射到 ClaimsIdentity

Azure VM 捕获(流程概述)

.net - 流响应在 Azure APIM 中不起作用

docker - 无法使用 Nginx 在 Blazor docker compose 配置中转发真实客户端 IP 地址

javascript - ASP .NET Core 使用多个 CORS 策略

c# - 我不能在 WebClient 上设置 If-Modified-Since 吗?