Problem with serving some static files in ASP.NET Core MVC

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"});
            });
        }
+4
source share
2 answers

, , , *.js.map, MVC.

+1

,

app.UseStaticFiles(new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(Path.Combine(env.WebRootPath, @"node_modules")),
            RequestPath = new PathString("/node_modules"),
            ServeUnknownFileTypes = true

        });

app.UseStaticFiles();

node_module wwwroot, node_module . - . /wwwroot.

. Microsoft -

0

Source: https://habr.com/ru/post/1653078/


All Articles