ASP.NET MVC没有提供默认文档 [英] ASP.NET MVC not serving default document
问题描述
我有一个ASP.NET MVC应用程序,其中的默认页面应该是index.html的是磁盘上的实际的文件。
I have an ASP.NET MVC application where the default page should be index.html which is an actual file on disk.
我可以使用www.mydomain.com/index.html所以我知道这将送达和存在,但如果我用www.mydomain.com我得到一个404浏览到该文件。
I can browse to the file using www.mydomain.com/index.html so I know it will be served and exists but if I use www.mydomain.com I get a 404.
我已确保默认文档在IIS7设置正确,我甚至都那么远,注释掉在我的Global.asax中定义的所有路线去保证,我没有一个路线导致此问题。
I have ensured that the default document is correctly set in IIS7 and I have even gone so far as to commented out all the routes defined in my global.asax to ensure I don't have a route causing this problem.
总结一下:
- 我对磁盘index.html文件和IIS7设置为使用index.html作为默认的文档。
- 如果我删除我的ASP.NET MVC应用程序,并留下index.html文件是担任预期的默认文档。
- 如果我发表我的ASP.NET MVC应用程序那么的index.html没有得到默认的文件服务。
有谁知道如何获得ASP.NET MVC服务的默认文档?
Does anyone know how to get ASP.NET MVC to serve the default document?
推荐答案
ASP.Net MVC路由是由的Global.asax
/ 全球控制.asax.cs
文件。外装即用的路由看起来是这样的:
ASP.Net MVC routing is controlled by the Global.asax
/ Global.asax.cs
files. The out-of-the-box routing looks like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
在没有指定路径,即得。 是www.domain.tld /
,路线为空字符串,,
。因此,路由查找与该名称的控制器。换句话说,它看起来没有名字在所有的控制器。当它发现没有这样的控制器,它提供了一个 404 NOT FOUND
错误页面。
When no path is specified, ie. www.domain.tld/
, the route is the empty string, ""
. Therefore the routing looks for a controller with that name. In other words, it looks for a controller with no name at all. When it finds no such controller it serves up a 404 NOT FOUND
error page.
要解决这个问题,可以映射路径有意义的,否则完全忽略这条路线,把控制权交给index.html文件:
To solve the problem, either map that path to something meaningful or else ignore that route entirely, passing control over to the index.html file:
routes.IgnoreRoute("");
这篇关于ASP.NET MVC没有提供默认文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!