【发布时间】:2021-04-09 08:46:09
【问题描述】:
我使用以下方法启用了 CORS:
private readonly string CorsPolicy = "CorsPolicy";
services.AddCors(options =>
{
options.AddPolicy(this.CorsPolicy, builder =>
{
builder.WithOrigins(this.Configuration.GetValue<string>("WebAppBaseUrl"))
.AllowAnyHeader()
.AllowAnyMethod()
.SetIsOriginAllowed(_ => true)
.AllowCredentials();
});
});
appsettings.json 条目:
"WebAppBaseUrl": "https://localhost:44372/"
但只有一个 GET 请求我收到以下错误:
从源“https://localhost:44372”访问“https://localhost:44343/api/pushNotification/GetMyPushNotifications/1/1”处的 XMLHttpRequest 已被 CORS 策略阻止:没有“访问控制-请求的资源上存在 Allow-Origin' 标头。
请注意,该项目有超过 50 个 GET 请求,并且在当前的 CORS 配置下所有这些请求都可以正常工作,只有这个特定的 GET 请求会给我这个 CORS 错误。
有什么想法吗?
【问题讨论】:
-
请注意,CORS 已启用。所有其他请求都做得很好。只有一个人给我这个问题。
标签: c# asp.net-core .net-core cors