[英].NET Core - CORS error even after enabling CORS
我正在嘗試調用 WebAPI 方法來獲取一些數據,但它拋出了一個Cross-Origin Read Blocking (CORB) blocked cross-origin response https://localhost:44332/api/Controller/Action with MIME type text/html.
即使我在 ConfigureServices 方法中啟用了 CORS 並在啟動時使用了 Configure 方法中的策略
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("AllowAll",
builder =>
{
builder
.WithOrigins("http://localhost:4200/")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
.....
app.UseCors("AllowAll");
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
原因可能是什么?
因此,基本上正如 CRice 和 johnny 評論的那樣, Internal server error
作為 CORS 錯誤傳播。
由於處理應用程序中的所有錯誤是一種很好的做法,因此這樣做將確保500 Internal Server Error
即使在出現異常的情況下也將完好無損,並且不會被屏蔽為 CORS 錯誤。
在這里可以更好地理解
這可能會有所幫助,
注意:URL 不得包含尾部斜杠 (/)。 如果 URL 以 / 結尾,則比較返回 false 並且不返回標頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.