我有一个现有的ASP.NET 3.5 WebForms项目,并已将ASP.NET MVC添加到该项目中.现有的页面工作得很好,新的控制器也是如此.观点.但是,当我部署到IIS 7时,默认文档(default.aspx)不再起作用.如果我明确地键入它,我可以得到它但是’xyz.com’不起作用 – 我得到404.相比之下,它在Cassini中工作正常.
如何在保留新MVC内容的同时再次使默认文档正常工作.
解决方法
我将以下内容添加到Global.asx.cs文件中,默认文档再次起作用.
public static void RegisterRoutes(RouteCollection routes)
{
// *** This Line ***
routes.IgnoreRoute(""); // Required for the default document in IIS to work
// *****************
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.MapRoute(
"Default",// Route name
"{controller}/{action}/{id}",// URL with parameters
new { controller = "Home",action = "Index",id = "" } // Parameter defaults
);
}
protected void Application_Start(Object sender,EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
