简体   繁体   English

CORS issue in Angular app deployed to Azure static web app

[英]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:官方文件:

API Management cross-domain policies API 管理跨域策略

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Angular 应用程序部署到 Azure Web 应用程序 - 但显示默认 Azure 页面 - Deployed angular app to Azure web app - But showing the default Azure page Azure Web 应用程序服务 - Angular 应用程序调用 login.microsoft.com CORS 问题 - Azure web app service - Angular App making calls to login.microsoft.com CORS Issue Angular 4 App调用Play Framework Web App时出现CORS问题 - CORS Issue with Angular 4 App calling Play Framework Web App 在 Azure Web App 上部署 Angular dist/ 显示默认屏幕 - Deployed Angular dist/ on Azure Web App showing me default screen Cors 使用 Azure AD 的 Angular 应用程序出现问题 - Cors Issue with Angular app which is using Azure AD 使用 Azure 静态应用程序部署时,角度应用程序的路由不起作用 - angular app's routing not working when deployed using Azure Static App 调用 Azure 函数的静态 Angular 应用程序。 这是一个安全问题吗? - Static Angular App calling Azure Functions. Is it a security issue? 重新加载路线在 Angular Azure static Z2567A5EC9305EB7AC2DEZ96 应用程序中返回 404 错误 - Reloading routes are returning 404 error in Angular Azure static web app 将 Angular 应用程序部署到 Azure Web 应用程序 Angular 9 的问题 - Issue Deploying Angular App to Azure Web Apps Angular 9 部署到Azure时,Angular 2应用程序上的错误404 - Error 404 on Angular 2 app when deployed to Azure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM