[英]CORS issue in Angular app deployed to Azure static web app
I have an Angular app that is deployed to Azure static web app, and .NET core web api also deployed to Azure using APIM service. I have an Angular app that is deployed to Azure static web app, and .NET core web api also deployed to Azure using APIM service. I am getting CORS issue when I launch the webpage and try to access the API.当我启动网页并尝试访问 API 时,我遇到了 CORS 问题。
I have added these code to my Startup.cs in web api:我已将这些代码添加到 web api 中的 Startup.cs 中:
In ConfigureServices在配置服务中
services.AddCors(options =>
{
options.AddPolicy(name: AllowSpecificOrigins, builder =>
{
builder.WithOrigins(Configuration.GetSection("CorsSettings:AllowedOrigins").Value.Split(","))
.AllowAnyMethod()
.AllowAnyHeader()
.SetIsOriginAllowed((host)=>true);
});
});
And in Configure并在配置
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors(AllowSpecificOrigins);
app.UseAuthentication();
app.UseAuthorization();
I have also added the origin to the CORS in the API App Service.我还在 API 应用服务中将原点添加到 CORS 中。
I am still getting CORS issue when trying to access the API from the web app.尝试从 web 应用程序访问 API 时,我仍然遇到 CORS 问题。
What am I missing?我错过了什么?
You told us you are using Azure APIM, so please the cross-domain policies.您告诉我们您正在使用 Azure APIM,所以请注意跨域策略。
It should be blocked by apim, so your cors settings in web application will not work.它应该被 apim 阻止,因此您在 web 应用程序中的 cors 设置将不起作用。
Official Doc:官方文件:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.