I have my own ASP.NET Core project. I serve content from a static folder (no problem). It processes images without cross-references (the CORS header appears). However, for some types of files, such as JSON, CORS headers are not displayed, and the client site cannot see the content. If I rename the file to an unknown type (e.g. JSONX), it will be served with CORS headers, no problem. How can I get this thing to serve everything with a CORS header?
I have the following CORS policy set in my Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials() );
});
services.AddMvc();
}
And here is my setup
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseCors("CorsPolicy");
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
var sfo = new StaticFileOptions() { ServeUnknownFileTypes = true, DefaultContentType = "application/octet-stream", RequestPath = "/assets"};
sfo.FileProvider = new PhysicalFileProvider(Program.minervaConfig["ContentPath"]);
app.UseStaticFiles(sfo);
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
Blake