我正在使用IIS 6.我認爲我的問題是我不知道如何使用routes.MapRoute路由到非控制器。ASP.NET MVC路由在html頁面啓動
我有一個像example.com這樣的url,我希望它能夠服務於index.htm頁面,而不是使用MVC。我該如何設置?在IIS中,我將index.htm作爲我的開始文檔,而我的global.asax具有標準的「默認」路由,它將其稱爲Home/Index。
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 = "" } // Parameter defaults
);
}
我加了這一點:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Context.Request.FilePath == "/") Context.RewritePath("index.htm");
}
它的工作原理。但這是最好的解決方案嗎?
我覺得有趣的是,您指出您正在運行IIS6。我不禁想到這將是解決方案中的關鍵因素 – 2009-04-27 19:09:45