Wednesday, April 1, 2020

Open up CORS for very specific domains in .NET Core 3.1.

This had this example:

public void ConfigureServices(IServiceCollection services)
{
   services.AddCors(options =>
   {
      options.AddPolicy(MyAllowSpecificOrigins,
      builder =>
      {
         builder.WithOrigins("http://example.com",
               "http://www.contoso.com")
               .AllowAnyHeader()
               .AllowAnyMethod();
      });
   });
   services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

 
 

MyAllowSpecificOrigins above is just a string and...

app.UseCors(MyAllowSpecificOrigins);

 
 

...needs to go inside of:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{

No comments:

Post a Comment