Warm tip: This article is reproduced from stackoverflow.com, please click
asp.net-core asp.net-mvc c#

ASP.NET Core .css Extension Goes To Controller

发布于 2020-03-27 10:14:36

I migrate my ASP.NET application to ASP.NET Core.

http://localhost:56623/js/jquery.js

works fine but

http://localhost:56623/css/bootstrap.css

calls my CategoryController's CheckIsCustomPage action so my application raise exception of course.

What can i do?

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "Category",
        template: "{sefLink}/{pageNumber}",
        defaults: new { controller = "Category", action = "CheckIsCustomPage", pageNumber = "1" }
    );

    routes.MapRoute(
        name: "Ajax",
        template: "ajax/{action}",
        defaults: new { controller = "Ajax" });

    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});
Questioner
Yargicx
Viewed
215
Owen Pauling 2019-07-03 21:12

Sounds like you don't have static files configured. If your routing is coming into play that's after the point that static files should be served. Prior to your:

app.UseMvc ...

Make sure you have:

app.UseStaticFiles();

And that your css folder is under wwwroot