Reputation: 415
Some background:
I create a new ASP.NET MVC 3 WebApplication.
Then I add a Webforms page: ~/ASPWebforms/Test.aspx
Then I edit the routing in the Global.asax file like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapPageRoute("Test", "Test/", "~/ASPWebforms/Test.aspx");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Now I type in my browser http://localhost:54847/Test
and everything works as expected.
The problem is that all other links look like that: http://localhost:54847/Test?action=Index&controller=Home
I also tried to change the order of the routes:
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 }
);
routes.MapPageRoute("Test", "Test/", "~/ASPWebforms/Test.aspx");
}
but then http://localhost:54847/Test
won't work anymore.
I'm expecting the link http://localhost:54874/Test
to go to ~/ASPWebforms/Test.aspx
And the other links work as usual mvc style {controller}/{action}/{id}
Thx for your help!
Upvotes: 0
Views: 892
Reputation: 415
I found a solution for the first problem on this page:
http://forums.asp.net/p/1589809/4028028.aspx
An interesting sentence from this page:
Please read the topic "Understanding the Outbound URL-Matching Algorithm" in Steve book.
Upvotes: 1
Reputation: 293
I can help with the second doubt.
The reason why it wont work is because the routes order is important.
http://msdn.microsoft.com/en-us/library/cc668201.aspx
whenever it finds a match, no more routes will be tested to that request.
Upvotes: 1