I have a web application using MVC 2 Preview 2 and after all routes are registered, I need to wrap each route in a decorator further down the chain. The problem is, doing so breaks routing. What ends up happening is the GetVirtualPath method will match falsely for other areas in the application (I'm using single-project areas). It doesn't matter if the decorator does anything useful or not. Using the following passthrough is all you need to break it.
public class RouteDecorator: RouteBase
{
readonly RouteBase _route;
public RouteDecorator(RouteBase route)
{
_route = route;
}
public override RouteData GetRouteData(HttpContextBase context)
{
return _route.GetRouteData(context);
}
public override VirtualPathData GetVirtualPath(RequestContext context, RouteValueDictionary values)
{
return _route.GetVirtualPath(context, values);
}
}
I'm assigning the decorator in a simple loop after all routes are registered.
var routes = RouteTable.Routes;
for (var i = 0; i < routes.Count; i++)
{
routes[i] = new RouteDecorator(routes[i]);
}
How can I safely insert a decorator without breaking routes and areas?
I have a reproduction solution available to download here. In the reproduction, the route decorator is commented out. Commenting it back in will break routing and the first dummy area's routing data will match the links that normally will correctly match only the corresponding namespace.