ASP.NET MVC 2 router matches correct area route but generates URL to the first registered area inste
Posted
by Sandor Drieënhuizen
on Stack Overflow
See other posts from Stack Overflow
or by Sandor Drieënhuizen
Published on 2010-05-03T00:16:04Z
Indexed on
2010/05/03
8:08 UTC
Read the original article
Hit count: 518
I'm working on a S#arpArchitecture 1.5 project, which uses ASP.NET MVC 2. I've been trying to get areas to work properly but I ran into a problem:
The ASP.NET MVC 2 routing engine matches the correct route to my area but then it generates an URL that belongs to the first registered area instead.
Here's my request URL:
/Framework/Authentication/LogOn?ReturnUrl=%2fDefault.aspx
I'm using the Route Tester from Phil Haack and it shows:
Matched Route: Framework/{controller}/{action}/{id}
Generated URL: /Data/Authentication/LogOn?ReturnUrl=%2FDefault.aspx using the route "Data/{controller}/{action}/{id}"
That's clearly wrong, the URL should point to the Framework area, not the Data area.
This is how I register my routes, nothing special there IMO.
private static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
AreaRegistration.RegisterAllAreas();
routes.MapRoute(
"default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}
The area registration classes all look like this. Again, nothing special.
public class FrameworkAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Framework";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Framework_default",
"Framework/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}
}
© Stack Overflow or respective owner