Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static Html page is not working after hosting in ASP.NET MVC

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

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

It's working fine when I access it like http://localhost:51353/Default.html

I host (include this static file) this project in my web server. But it's showing error:

404 Error

Is there any additional configuration needed to do this ?

like image 895
Ragesh S Avatar asked May 28 '15 04:05

Ragesh S


1 Answers

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

It worked locally because you may have set it as start page in Visual Studio. For this to work you need to tell MVC to ignore the route if its for the HTML page or ASPX page. Find your routing configuration section, it’s in RouteConfig.cs under the App_Start folder. Use the IgnoreRoute() method to tell Routing to ignore the specific paths.

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

Now MVC ignores a request to load the Default.html page and leaves IIS to handle the resource.

like image 63
Rahul Nikate Avatar answered Nov 09 '22 23:11

Rahul Nikate