簡體   English   中英

身份服務器-為承載選項配置CORS

[英]identity Server - Configuring CORS for bearer options

我正在測試從其他域到API服務器的jquery ajax調用。 不幸的是,我遇到一個OPTIONS錯誤。 這是我的請求代碼:

$.ajax({
    url: "https://localhost:44356/api/Default/",
    headers: {
        "Authorization": "Bearer " + user.access_token
    },
    success: function (res) {
        logAjaxResult(res);
    },
    error: function() {
        logAjaxResult('Error');
    }
}))

這使

XMLHttpRequest cannot load https://localhost:44356/api/Default/. Response for preflight has invalid HTTP status code 405.

通常,這是一個簡單的修復程序-我安裝Microsoft.AspNet.WebApi.Cors,設置提供程序並始終允許OPTIONS通過。 我也可以在Identity Server框中看到通常如何執行此操作,因為可以注冊一個CorsProvider。 但是,我的問題是在API框中,我正在使用IdentityServerBearerTokenAuthenticationOptions,但沒有看到CORs選項。 當我嘗試設置WebAPI.cors提供程序時,雖然出現錯誤,指出服務器上設置了多個允許來源。 這向我表明(如果我錯了,請糾正我),WebApi框以某種方式從我的身份服務器框中獲取了CORs設置,並已將其注冊為權限。 這是正確的嗎?

如何配置以允許通過app.UseIdentityServerBearerTokenAuthentication(options)執行預檢請求?

非常感謝

當我發現文檔使用時,此問題已解決

Microsoft.Owin.Cors

我正在使用包裹

Microsoft.AspNet.WebApi.Cors

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM