I had a problem with ASP.NET Core not serving static files. I have part of my application in node_modules under wwwroot. For the most part, all files work, but there are exceptions. * .js.map are redirected to the MVC, serving my MVC pages instead of the actual files. As a result, I get errors in the browser, such as
Failed to parse SourceMap: http: // localhost: 5000 / node_modules / bootstrap / bootstrap.min.css.map
Following the same route, my web fonts, such as one of them with Bootstrap, are also not properly served, and are also processed by MVC middleware instead of static middleware. It seems that all the files that are in node_modules should be redirected to my middleware static files, which is not happening. Thank.
public void Configure (IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole ();
if (env.IsDevelopment ())
{
app.UseDeveloperExceptionPage ();
}
app.UseStaticFiles ();
app.UseStaticFiles (new StaticFileOptions
{
FileProvider = new PhysicalFileProvider (Path.Combine (env.WebRootPath, @ "node_modules")),
RequestPath = new PathString ("/ node_modules"),
ServeUnknownFileTypes = true
});
app.UseMvc (config =>
{
config.MapRoute ("Default", "{controller} / {action} / {id?}",
new {controller = "Home", action = "Index"});
config.MapRoute ("AngularDeepLinkingRoute", "{* url}",
new {controller = "Home", action = "Index"});
});
}
source
share