I have a web application using MVC 2 Preview 2 and after registering all the routes I need to wrap each route in the decorator further down the chain. The problem is that this interrupts routing. As a result, the GetVirtualPath process will be falsely used for other areas of the application (I use single-project areas). It doesn't matter if the decorator does anything useful or not. Using the following pass-through 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 assign the decorator to a simple loop after registering all routes.
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 playback solution to download here . During playback, the route decoder is commented out. By commenting on this, you will break the routing, and the first routing data in the dummy area will correspond to links, which usually will correctly only match the corresponding namespace.
Daniel Crenna
source share