0
從ASP .NET核心的Web應用程序,我試圖讓使用React.js一個Drupal的Web API的調用,但我得到以下錯誤:ASP .NET異步核心部分觀點
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '[my-drupal-api]' is therefore not allowed access.
我已嘗試將以下內容添加到我的Startup.cs中:
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
app.UseCors("CorsPolicy");
我仍然收到相同的錯誤。
我很好奇,如果有另一種方式來做這個服務器端,沒有反應。有沒有辦法做一個異步局部視圖,將加載從Drupal web api返回的數據,而不會延遲頁面的其餘部分的負載?
謝謝!
感謝您的答覆。我仍然得到相同的錯誤:無法加載http://1.1.1.1/api/news:沒有'Access-Control-Allow-Origin'標題出現在請求的資源上。原因'http:// localhost:11111'因此不被允許訪問。 – Primico
當應用程序託管在真實服務器上而不是本地計算機上時,是否出現此問題?您可能有興趣閱讀此也https://stackoverflow.com/questions/44544425/getting-error-no-access-control-allow-origin-header-is-present-on-the-reques –