我已将 netcoreapp 从 2.1 更新到 2.2,但无法弄清楚如何让 CORS 再次工作。以前使用过如下配置:
services.AddCors(o => o.AddPolicy("App", builder =>
builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
Run Code Online (Sandbox Code Playgroud)
升级到 2.2 后.AllowAnyOrigin()不再支持。我已将配置更改为:
services.AddCors(o => o.AddPolicy("App", builder =>
builder
.WithOrigins("http://localhost:8080", "ionic://localhost", "http://localhost") // (development, cordova-ios, cordova-android)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
));
}
Run Code Online (Sandbox Code Playgroud)
此外,我正在使用https://github.com/ionic-team/cordova-plugin-ionic-webview插件用于cordova。android 和 ios 的 webview 来源如下:http://localhost , ionic://localhost
我在 Android 上收到以下错误:
Access to XMLHttpRequest at 'https://my-host-app.azurewebsites.net/api/user/profile' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested
Run Code Online (Sandbox Code Playgroud)
请求头:
:authority: my-host-app.azurewebsites.net …Run Code Online (Sandbox Code Playgroud)