在ASP.NET MVC中托管后,静态Html页面无法正常工作

Rag*_*h S 8 c# asp.net iis asp.net-mvc asp.net-mvc-4

在我的MVC项目中,Default.html根文件夹中有一个文件,并将此文件路由为默认路由.

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

当我访问它时,它工作正常 http://localhost:51353/Default.html

我在我的Web服务器中托管(包含此静态文件)此项目.但它显示错误:

404错误

是否需要执行其他配置?

Rah*_*ate 11

如果要static HTML pageASP.net MVC项目中托管,则需要配置路由配置MVC以忽略对这些页面的请求.

它在本地工作,因为您可能已将其设置为Visual Studio中的起始页.为了使这个工作你需要告诉MVC忽略路由,如果它为HTML pageASPX page.找到您的路由配置部分,它位于RouteConfig.csApp_Start文件夹下.使用该IgnoreRoute()方法告诉Routing忽略特定路径.

routes.IgnoreRoute("Default.html"); //ignore the specific HTML page
Run Code Online (Sandbox Code Playgroud)

现在MVC忽略加载Default.html页面的请求并离开IIS处理资源.