简体   繁体   中英

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错误

Is there any additional configuration needed to do this ?

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.

根据MVC路由,您无法将静态文件映射到路由表,因为当MVC路由机制提供直接访问物理存在的静态文件时。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM