Why does the order of route mapping matter when mixing MVC and webforms?
Curious why declaring a MapPageRoute before the default MVC route causes problems with UrlHelper.GenerateUrl.
I started with this in my Global.asax.cs:
public static void RegisterRoutes(RouteCollection routes)
{
开发者_StackOverflow 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 } );
}
Any reference in a view to a default declaration like @Html.BeginForm()
, or a controller call result like RedirectToAction("Index", "Errors", new {fault = "itemMissing"} );
would yield the URL "oldform.aspx".
When I swap the order of the default MVC route with the page route, it works as expected.
This is for asp.net web forms routing. you can see
http://msdn.microsoft.com/en-us/library/system.web.routing.routecollection.mappageroute.aspx
精彩评论