[英]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. 在我的MVC项目中,根文件夹中有一个
Default.html
文件,并将此文件作为默认路由路由。
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
当我访问
http://localhost:51353/Default.html
时它工作正常
I host (include this static file) this project in my web server. 我在我的Web服务器中托管(包含此静态文件)此项目。 But it's showing error:
但它显示错误:
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. 如果要在
ASP.net MVC
项目中托管static HTML page
,则需要在MVC
配置路由配置以忽略对这些页面的请求。
It worked locally because you may have set it as start page in Visual Studio. 它在本地工作,因为您可能已将其设置为Visual Studio中的起始页。 For this to work you need to tell
MVC
to ignore the route if its for the HTML page
or ASPX page
. 为此,您需要告诉
MVC
忽略HTML page
或ASPX page
的路由。 Find your routing configuration section, it's in RouteConfig.cs
under the App_Start
folder. 寻找你的路由配置部分,它在
RouteConfig.cs
下App_Start
文件夹。 Use the IgnoreRoute()
method to tell Routing to ignore the specific paths. 使用
IgnoreRoute()
方法告诉Routing忽略特定路径。
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
忽略了加载Default.html
页面的请求,并让IIS
处理资源。
根据MVC路由,您无法将静态文件映射到路由表,因为当MVC路由机制提供直接访问物理存在的静态文件时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.