Html static page not working after hosting in ASP.NET MVC

In my MVC project, the root.html file is in the root folder and route this file as the default route.

  routes.MapRoute( name: "", url: "Default.html" //, //defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 

It works fine when I access it as http://localhost:51353/Default.html

I host (including this static file) this project on my web server. But he shows an error 404 Error

Is additional configuration required for this?

please, help

+8
c # asp.net-mvc iis asp.net-mvc-4
source share
2 answers

If you want to host a static HTML page in an ASP.net MVC project, then you need to configure the routing configuration in MVC to ignore requests for these pages.

It worked locally because you might have installed it as a start page in Visual Studio. To do this, you need to tell MVC ignore the route if it is for an HTML page or ASPX page . Locate the routing configuration section located in RouteConfig.cs in the App_Start folder. Use the IgnoreRoute() method to IgnoreRoute() Routing to ignore specific paths.

 routes.IgnoreRoute("Default.html"); //ignore the specific HTML page 

MVC now ignores the request to load the Default.html page and leaves IIS to process the resource.

+11
source share

According to MVC tracing, you cannot map static files in the routing table, because when MVC Routing Machanism provides direct access to physically existing static files.

0
source share

All Articles