<i id='B136m'><tr id='B136m'><dt id='B136m'><q id='B136m'><span id='B136m'><b id='B136m'><form id='B136m'><ins id='B136m'></ins><ul id='B136m'></ul><sub id='B136m'></sub></form><legend id='B136m'></legend><bdo id='B136m'><pre id='B136m'><center id='B136m'></center></pre></bdo></b><th id='B136m'></th></span></q></dt></tr></i><div id='B136m'><tfoot id='B136m'></tfoot><dl id='B136m'><fieldset id='B136m'></fieldset></dl></div>

    <small id='B136m'></small><noframes id='B136m'>

    <tfoot id='B136m'></tfoot>
  1. <legend id='B136m'><style id='B136m'><dir id='B136m'><q id='B136m'></q></dir></style></legend>

    • <bdo id='B136m'></bdo><ul id='B136m'></ul>

      Core 2.1 拒绝使用 Access-Control-Expose-Headers 响应:*

      时间:2023-09-14
    1. <small id='2636q'></small><noframes id='2636q'>

      <i id='2636q'><tr id='2636q'><dt id='2636q'><q id='2636q'><span id='2636q'><b id='2636q'><form id='2636q'><ins id='2636q'></ins><ul id='2636q'></ul><sub id='2636q'></sub></form><legend id='2636q'></legend><bdo id='2636q'><pre id='2636q'><center id='2636q'></center></pre></bdo></b><th id='2636q'></th></span></q></dt></tr></i><div id='2636q'><tfoot id='2636q'></tfoot><dl id='2636q'><fieldset id='2636q'></fieldset></dl></div>

              <tbody id='2636q'></tbody>

            • <bdo id='2636q'></bdo><ul id='2636q'></ul>
            • <legend id='2636q'><style id='2636q'><dir id='2636q'><q id='2636q'></q></dir></style></legend>
                <tfoot id='2636q'></tfoot>
                本文介绍了Core 2.1 拒绝使用 Access-Control-Expose-Headers 响应:*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我一定是在这里做错了,但我想不通;据我所知,这似乎是一个 CORS 问题.我需要将 Access-Control-Expose-Headers: * 暴露给任何来源,但 dotnet core 2.1 没有达到我的预期.

                I must be doing something wrong here but I can't figure it out; it seems to be a CORS issue from what I can tell. I need to expose Access-Control-Expose-Headers: * to any origin but dotnet core 2.1 isn't doing what I expect.

                相关Startup.cs代码:

                Relevant Startup.cs code:

                        public void ConfigureServices(IServiceCollection services)
                        {
                            //Mapping settings to POCO and registering with container
                            var settings = new AppSettings.ReportStorageAccountSettings();
                            Configuration.Bind(nameof(AppSettings.ReportStorageAccountSettings), settings);
                
                            services.AddCors(options =>
                            {
                                options.AddPolicy("AllowAll",
                                    builder =>
                                    {
                                        builder
                                            .AllowAnyHeader()
                                            .AllowAnyMethod()
                                            .AllowAnyOrigin()
                                            .AllowCredentials();
                                    });
                            });
                            services.AddSingleton(settings);
                            services.AddApiVersioning();
                            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
                        }
                
                        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
                        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
                        {
                            if (env.IsDevelopment())
                            {
                                app.UseDeveloperExceptionPage();
                            }
                            else
                            {
                                app.UseHsts();
                            }
                
                            app.UseCors("AllowAll");
                            app.UseHttpsRedirection();
                            app.UseMvc();
                        }
                

                此应用程序托管在 Azure 中,我在 Azure 中的 CORS 设置中添加了一个 * 条目,只是为了更好地衡量.现在,每当客户端应用程序(也托管在 Azure 中)发出发布请求时,都无法通过 JS 访问标头,并且响应中不存在 Access-Control-Expose-Headers: *.但是,当我检查网络响应和使用 Fiddler 时,我可以看到标头.我已经尝试使用 Axios 和 Jquery 来访问标题以排除 JS 的任何问题.我在这里做错了什么?

                This application is hosted in Azure and I have added a * entry to the CORS settings in Azure just for good measure. Now, whenever the client application (which is also hosted in Azure) makes a post request, the headers are not accessible via JS and Access-Control-Expose-Headers: * is not present in the response. However, I can see the headers when I inspect the network response and when using Fiddler. I have tried Axios and Jquery for accessing the headers to rule out any issues with the JS. What am I doing wrong here?

                在控制器中我回复:

                 Response.Headers.Add("Location", $"api/someLocation");
                 return StatusCode(StatusCodes.Status202Accepted);
                

                推荐答案

                CorsPolicyBuilderAllowAnyHeader 方法配置 Access-Control-Allow-Headers 响应头,即仅用于 预检请求.Access-Control-Expose-Headers 响应头是需要的,使用 WithExposedHeaders.

                这是一个完整的例子:

                services.AddCors(options =>
                {
                    options.AddPolicy("AllowAll", builder =>
                    {
                        builder.AllowAnyHeader()
                               .AllowAnyMethod()
                               .AllowAnyOrigin()
                               .AllowCredentials()
                               .WithExposedHeaders("Location"); // params string[]
                    });
                });
                

                这篇关于Core 2.1 拒绝使用 Access-Control-Expose-Headers 响应:*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:CORS POST 请求不起作用 - 选项(错误请求) - 不允许来源 下一篇:ASP.NET 中的 CORS 问题

                相关文章

                <i id='rsN3G'><tr id='rsN3G'><dt id='rsN3G'><q id='rsN3G'><span id='rsN3G'><b id='rsN3G'><form id='rsN3G'><ins id='rsN3G'></ins><ul id='rsN3G'></ul><sub id='rsN3G'></sub></form><legend id='rsN3G'></legend><bdo id='rsN3G'><pre id='rsN3G'><center id='rsN3G'></center></pre></bdo></b><th id='rsN3G'></th></span></q></dt></tr></i><div id='rsN3G'><tfoot id='rsN3G'></tfoot><dl id='rsN3G'><fieldset id='rsN3G'></fieldset></dl></div>

                <small id='rsN3G'></small><noframes id='rsN3G'>

                1. <tfoot id='rsN3G'></tfoot>
                    <bdo id='rsN3G'></bdo><ul id='rsN3G'></ul>

                    <legend id='rsN3G'><style id='rsN3G'><dir id='rsN3G'><q id='rsN3G'></q></dir></style></legend>