I have an MVC6 site running in Visual Studio 2015 RC
I've got some static HTML files I want to serve to another website. I want to add CORS support (without having to add a controller and add CORS that way).
Does anyone know how to do this please?
In Startup.cs
Configure the policy in ConfigureServices ...
public void ConfigureServices(IServiceCollection services)
{
options.AddPolicy("AllowEverything", builder =>
{
builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials();
});
}
Then in Configure set the app to use the policy, then set UseStaticFiles ...
Ensure that UseStaticFiles() comes after UseCors - at least in the version I'm using (installed with Visual Studio 2015 RC) it needs to come after UseCors()
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseCors("AllowEverything");
app.UseStaticFiles();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With