Question

I've got a localization httphandler that's running in the context of my ASP.Net MVC2 Content folder (part of what it's doing is compiling .less files that are in /Content/css). My default route for this particular set of requests looks like this:

context.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

context.MapRoute(
    "Area_default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    new { controller = new VirtualDirectoryConstraint("VDirectory1") },
    new string[] { "Namespace.One.MVC" }
);

(As an aside - I don't think it's relevant, but just in case - the VirtualDirectoryConstraint rejects matches on this route if the request is not coming from the passed-in application path/virtual directory)

With this configuration a call to http://server.net/VDirectory1/Content/css/LessCompiler.axd fails because there's no ContentController class. All well and good.

When I add

context.Routes.IgnoreRoute("{Content}/{*pathInfo}");

that call succeeds, but subsequent calls to

http://server.net/VDirectory1/Localization/ClientScript/en-US.js

and

http://server.net/VDirectory1/Authorization/ClientScript

fail. Looking at Phil Haack's RouteDebugger tool, those calls are matching the Content IgnoreRoute route:

True    {Content}/{*pathInfo}   (null)  (null)  (null)

and are therefore not being routed to the LocalizationController and AuthorizationController, respectively.

Clearly I'm misunderstanding something about how the IgnoreRoute is supposed to be used and why that particular IgnoreRoute is matching those requests. What am I missing?

Was it helpful?

Solution

Shouldn't your IgnoreRoute use Content instead of {Content} ?

context.Routes.IgnoreRoute("Content/{*pathInfo}");

At the moment, {Content} is probably being expanded as a variable to nothing, which makes the pathinfo match everything.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top