0

我試圖用我的應用程序連接到Azure Active Directory,但出現此錯誤: 處理請求時發生未處理的異常。OpenIdConnectAuthenticationHandler:message.State爲空或空。當連接到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,在我的項目,並添加URL中的可視化Studio將我作爲回覆URL。

之前,當我不得不配置一個不正確的URL,這使我對Microsoft登錄網站,稱該URL沒有任何註冊的名稱相符,所以我知道它至少得那麼遠。

我也應該說我正在關注this post,但是使用了新的門戶。我無法訪問經典門戶。

如何解決此錯誤?

謝謝你的幫助。

+0

您是否修復了此問題? –

回答

0

當你所提到的新門戶,請確保它意味着new Azure portal 而不是new register apps portal這對於Azure AD v2.0 endpoint

Before, when I had an incorrect URL configured, it led me to the Microsoft login site that said that the URL didn't match any registered ones, so I know it at least got that far.

您在代碼中使用的redirect_url應該與您在Azure上註冊的應用程序相關聯。

我也跟着這個鏈接,該項目對我來說效果很好。您可以從here下載該項目。請先爲Azure上的應用配置redirect_url(https://localhost:44397/signin-aad),然後根據您的應用設置appsetting,然後您可以使用Url訪問應用https://localhost:44397