Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do route decorators break routing in ASP.NET MVC 2?
    primarykey
    data
    text
    <p>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.</p> <pre><code>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); } } </code></pre> <p>I'm assigning the decorator in a simple loop after all routes are registered.</p> <pre><code>var routes = RouteTable.Routes; for (var i = 0; i &lt; routes.Count; i++) { routes[i] = new RouteDecorator(routes[i]); } </code></pre> <p>How can I safely insert a decorator without breaking routes and areas?</p> <p>I have a reproduction solution available <a href="http://dimebrain.com.s3.amazonaws.com/RouteDecoratorIssueRepro.zip" rel="nofollow noreferrer">to download here</a>. 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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload