azure 删除从我的应用程序服务返回的 Access-Control-Allow-Origin 标头

2024-01-08

我有两个服务在 Azure 上运行:

  • a 网络服务(角度应用程序/expressjs)
  • an 应用服务(ASPNET核心应用程序)

All the 网络服务所做的是查询应用服务对于以下端点:my-app-service.azurewebsites.net/.well-known/openid-configuration

My 应用服务已设置为允许来自我的 CORS 请求网络服务在代码级别通过 IdentityServer4 dll 并且正如许多网站中提到的那样,我确实确保 CORS 设置不会被覆盖网络配置 or 天蓝色CORS管理页面.

这些是我的 HTTP 请求标头:

Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate
Host:my-app-service.azurewebsites.net
Origin:http://my-web-service.azurewebsites.net
Pragma:no-cache
Referer:http://my-web-service.azurewebsites.net/

这些是我的 HTTP 响应标头

Content-Encoding:gzip
Content-Type:application/json
Date:Fri, 05 Jan 2018 17:22:53 GMT
Server:Kestrel
Set-Cookie:ARRAffinity=da4c4ff244aae03ae3c7548f243f7c2b5c22567a56a76a62aaebc44acc7f0ba8;Path=/;HttpOnly;Domain=Host:my-app-service.azurewebsites.net
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Powered-By:ASP.NET

正如你所看到的,没有一个Access-Control-*标头存在。我已向 asp.net core 应用程序管道添加了一个自定义中间件来跟踪响应标头,我可以清楚地看到它们的存在。

因此,Azure 正在某个地方剥离我的标头,而我现在没有更多线索可以查看。


更新#1

我忘记指定如果一切都在本地主机上运行,​​那么它就可以正常工作。但在 Azure 上却没有。

更新#2

我的身份服务器4代码

[...]
using Microsoft.IdentityModel.Tokens;
using IdentityServer4.EntityFramework.Mappers;
using IdentityServer4.EntityFramework.DbContexts;
using IdentityServer4;

namespace My.IdentityServer4
{
    public class Startup
    {
        private const string DEFAULT_DEVELOPMENT_AUTHORITY = "http://localhost:5000/";

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            // [... add db context. identity framework, default token provider]
            services.AddMvc();

            // Cors ( not required, identity server 4 manages it internally )
            //services.AddCors(options =>
            //    options.AddPolicy("AllowAllOrigins", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));

            string connectionString = Configuration.GetConnectionString("SQLServer");
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddAspNetIdentity<ApplicationUser>()
                // this adds the config data from DB (clients, resources)
                .AddConfigurationStore(options =>
                {
                    options.ConfigureDbContext = builder =>
                        builder.UseSqlServer(connectionString,
                            sql => sql.MigrationsAssembly(migrationsAssembly));
                })
                // this adds the operational data from DB (codes, tokens, consents)
                .AddOperationalStore(options =>
                {
                    options.ConfigureDbContext = builder =>
                        builder.UseSqlServer(connectionString,
                            sql => sql.MigrationsAssembly(migrationsAssembly));

                    // this enables automatic token cleanup. this is optional.
                    options.EnableTokenCleanup = true;
                    options.TokenCleanupInterval = 30;
                });

            services.AddAuthentication()
                .AddOpenIdConnect("oidc", "OpenID Connect", options =>
                {
                    //TODO: enable HTTPS for production
                    options.RequireHttpsMetadata = false;
                    options.Authority = DEFAULT_DEVELOPMENT_AUTHORITY;
                    options.ClientId = "app"; // implicit
                    options.SaveTokens = true;
                    options.TokenValidationParameters = new TokenValidationParameters
                    {
                        NameClaimType = "name",
                        RoleClaimType = "role"
                    };
                });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // [... Some stuff before not useful for this snippet]

            // For debug purposes, print out request and response headers
            app.UseMiddleware<LogHeadersMiddleware>();

            app.UseStaticFiles();

            // Cors ( not required, identity server 4 manages it internally )
            //app.UseCors("AllowAllOrigins");

            app.UseIdentityServer();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }



    public class LogHeadersMiddleware
    {
        private readonly RequestDelegate next;
        private readonly ILogger<LogHeadersMiddleware> logger;

        public LogHeadersMiddleware(RequestDelegate next, ILogger<LogHeadersMiddleware> logger)
        {
            this.next = next;
            this.logger = logger;
        }

        public async Task Invoke(HttpContext context)
        {
            await this.next.Invoke(context);

            logger.LogInformation(
                $"------------------------\r\n" +
                $"*** Request headers ****\r\n" +
                string.Join("\r\n", context.Request.Headers.OrderBy(x => x.Key)) + "\r\n" +
                $"*** Response headers ***\r\n" +
                string.Join("\r\n", context.Response.Headers.OrderBy(x => x.Key)) + "\r\n" +
                $"------------------------\r\n");

        }
    }
}

更新 #3 - Azure 服务应用程序上的 CORS 未设置

有什么提示吗?谢谢


@NoName 找到了我的问题的答案thread https://stackoverflow.com/questions/48230736/http-headers-removed-azure-web-app/48230859#48230859.

简而言之,必须在 Azure 上启用 https 才能工作。

不过,如果日志中出现来自 Azure 的警告,我们将不胜感激。我不会在这件事上浪费时间的:S

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

azure 删除从我的应用程序服务返回的 Access-Control-Allow-Origin 标头 的相关文章

  • Azure无法访问React Web应用程序中的env变量

    几年前我看到有一个类似的问题 但超链接答案已被微软关闭 我有一个使用 create react app 创建的 React 应用程序 它已经部署到heroku并加载一些环境变量来访问谷歌地图等 这一切对于heroku来说都工作得很好 我已经
  • App Insights 升级到 2.5 后,Azure 应用服务将无法启动

    我有一个存储库 它使用应用程序洞察来记录有关在 ASP NET 中运行的服务的信息 我们有一些 ASP NET Core 2 0 站点以及一些完整框架的 asp net 4 应用程序 随着应用程序洞察 2 5 的发布 我们在核心站点中获得了
  • 由于“请求缓慢”限制,Azure 网站不断重新启动

    我在西欧和标准模式下设置了一个天蓝色网站 世界标准时间 UTC 今天 2014 年 1 月 30 日凌晨 03 00 突然开始不断重新启动应用程序池 关闭原因是托管环境 我在 eventlog xml 中有很多这样的事件
  • .Net Core IdentityServer4 获取经过身份验证的用户

    我试图弄清楚如何使用 Net Core 2 从身份服务器 4 检索登录用户 我的身份验证当前正在工作 我只是想弄清楚如何从 HTTP 上下文中检索声明身份 services AddAuthentication options gt opti
  • 无法将预编译、合并的 webapp 部署到 Azure

    我正在尝试将 ASP NET Web 应用程序部署到 Azure 它是 Web 表单 MVC 和 WebAPI 的混合体 并且有大量的 aspx ascx 文件 因此它们确实需要预编译 否则每次部署都会使网站运行缓慢一段时间 我正在尝试通过
  • Get-AzureStorageBlob 抛出找不到您的 azure 存储凭据

    我刚刚开始使用 Azure 在使用 PowerShell cmdlet 处理我的存储帐户时遇到问题 我已经创建了一个存储帐户并在该存储帐户中创建了一个容器 接下来 我安装了 Azure Powershell SDK 和命令让等 并导入了pu
  • 使用 dotnet pack 包含所有依赖项

    有什么办法可以强制dotnet pack包含所有引用的程序集 project json 中的所有依赖项 我相信这是相关的 https github com dotnet cli issues 1290 https github com do
  • Azure Policy:删除资源组上的锁定

    我尝试使用 Azure Policy 检查生产订阅中的所有资源组是否都有 CanNotDelete 锁 我制定了一项政策 其灵感来自于这个问题 https stackoverflow com questions 54883610 how t
  • 使用服务主体连接 Azure SQL Server

    我想通过 Python 使用 Azure 服务主体连接 Azure SQL 数据库 请帮我 我可以使用服务主体通过 ADF 连接它 有一个图书馆Microsoft Azure Active Directory Authentication
  • 如何使用postman调用REST API进行azure文件存储?

    我想通过postman调用azure的文件存储相关的REST API 以下是我提出请求的方式 我正在请求列出文件存储帐户中的所有共享 如下所述 https learn microsoft com en us rest api storage
  • AngularJS 忽略一些标头

    我正在玩一点 Angular 遇到了一个小问题 我正在尝试为http响应设置一个自定义标头 然后在角度方面读取它的值 标头已设置 我确信这一点 因为 chrome 的调试工具确认了 这意味着服务器端没问题 到目前为止 一切都很好 当我尝试通
  • Identity Server 4:添加访问令牌的声明

    我正在使用 Identity Server 4 和隐式流 并且想要向访问令牌添加一些声明 新的声明或属性是 tenantId 和 langId 我已将 langId 添加为我的范围之一 如下所示 然后通过身份服务器请求 但我也获得了tena
  • EF Core 模型构建约定

    在 EF6 中 可以在模型构建期间根据属性类型定义约定 就像这样 public interface IEntity Guid Id get public class MyEntity IEntity public Guid Id get s
  • 当后端托管在 Azure 上时,create-react-app 代理请求失败并显示 404

    我在设置 create react app 应用程序来代理对 Microsoft azure 上的测试托管的请求时遇到了一些麻烦 我在应用程序的 package json 中设置了代理 如下所示 proxy api target https
  • 在 .NET Core 上通过 MEF 将参数传递给插件构造函数?

    我花了几个小时试图弄清楚如何通过 MEF System Composition 将参数传递给插件构造函数 但一切都无济于事 不用说 相关文档很少 查看源代码也没有帮助 这曾经非常容易做到 使用 CompositionHost Compose
  • ASP.NET Core中间件如何进行DI?

    我正在尝试将依赖项注入到我的中间件构造函数中 如下所示 public class CreateCompanyMiddleware private readonly RequestDelegate next private readonly
  • SignalR .Net Core 3.1 Web 应用程序无法在本地 IIS 上运行

    尝试使用 ASP Net Core 3 1 和 Angular 基于在线示例创建聊天 以下内容在 IIS Express 上运行良好 但在本地 IIS 上运行不佳 错误信息 WebSocketTransport js 85 WebSocke
  • Asp.net Core 授权重定向未发生

    我正在尝试在 Asp net core 应用程序 dnx 4 5 中使用 cookie 身份验证 请注意 因为我有自定义身份验证机制 半径 所以我没有使用核心身份验证提供的开箱即用机制 当用户未经身份验证时 我想重定向到登录页面 我在 St
  • Azure 函数异常 - 将日志写入表存储时出错:Microsoft.Azure.Cosmos.Table.StorageException

    我有一个 azure 函数 它与 blob 存储通信以读取上次同步日期时间 然后基于此从 Cosmos 数据库中读取数据 很少有交互可以正常工作 并且在某些情况下会随机抛出以下异常 将日志写入表存储时出错 Microsoft Azure C
  • Azure 应用服务计划 - 分钟/天是什么意思?

    我有 ASMX Web 服务 带有 1 个 MSSQL 数据库和一个表 我目前已将其部署到 Azure应用服务我已从免费试用升级到按使用付费计划 我真的很困惑应用服务计划 ASMX 服务由桌面应用程序调用 它只有几个方法 只是从数据库获取和

随机推荐