2011-04-12 34 views
0

奇怪爲什麼在默認的MVC路由導致UrlHelper.GenerateUrl出現問題之前聲明MapPageRoute。爲什麼混合MVC和webforms時路由映射的順序很重要?

我開始與這在我的Global.asax.cs:

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.MapRoute("MyApp", "home/my-app", new { controller = "Home", action = "MyApp" }); 
    routes.MapPageRoute("MyOldWebForm", "oldform.aspx", "~/WebForms/OldForm.aspx"); 

    routes.MapRoute(
     "Default", 
     "{controller}/{action}/{id}", 
     new { controller = "Site", action = "Index", id = UrlParameter.Optional }); 
} 

在視圖中默認的聲明像@Html.BeginForm(),或控制器調用結果像RedirectToAction("Index", "Errors", new {fault = "itemMissing"});將產生的URL「的任何引用oldform.aspx 」。

當我使用頁面路由交換默認MVC路由的順序時,它按預期工作。

回答