Ash*_*mar 8 azure cors azure-app-service-envrmnt asp.net-core-webapi
我写了一些代码来处理CORS了我的Web Api(.Net Core)。这些代码可以完美地在我的本地和测试服务器(Azure应用程序服务)上运行,但不适用于生产环境(Azure应用程序服务)。它给出了错误-
XMLHttpRequest无法加载http://myapiproduction.co/token。所请求的资源上没有“ Access-Control-Allow-Origin”标头。因此,不允许访问源“ http://myuidashboard.co ”。
我在中给出了正确的允许的原始网址appsettings.Production.json。我*从CORSAzure应用程序服务(生产环境)部分中删除了所有值()。
当我们从应用程序服务的CORS部分中删除所有内容后,我们的代码逻辑应该可以正常工作,因为一次只有一个中间件可以运行应用程序服务的CORS中间件或Web Api代码逻辑。
网络Api(Startup.cs)-
var allowedOriginsArr = Configuration["AppSettings:AllowedOrigins"].Split(','); //Example- "http://myuidashboard.co"
services.AddCors(options =>
{
options.AddPolicy("AllowAllCorsPolicy",
builder => builder.WithOrigins(allowedOriginsArr)
.WithMethods("GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS")
.AllowAnyHeader()
.WithExposedHeaders("X-Auth-Token")
.AllowCredentials());
});
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是-我需要做其他设置来禁用Azure应用服务的CORS中间件吗?我想CORS完全通过代码(Api逻辑)进行控制。
小智 -2
我的天蓝色网站是用 vb.net 编程的,但最终我必须这样做,然后它就起作用了:
Dim strMethod As String
strMethod = Request.HttpMethod.ToUpper
If InStr(strMethod, "OPTIONS") Then
Response.Flush()
End If
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
555 次 |
| 最近记录: |