Add HTTP response header (Access Control Allow Origin)

Asked

Viewed 23 times

0

In my ASP.NET CORE MVC application I have the dist folder in wwwroot:

pasta dist

According to the documentation Static Files in ASP.NET CORE configured the startup class by adding an http response header:

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

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
        }

        
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    // using Microsoft.AspNetCore.Http;
                    ctx.Context.Response.Headers.Append(
                         "Access-Control-Allow-Origin", "*");
            }
            });

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
            });
        }
    }

Example (functions.json):

response Headers

What I’m missing ?

  • 1

    CORS. https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-5.0missing

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.