Route impedes delivery of /Content/*

Last post 03-13-2008 11:06 PM by Haacked. 4 replies.

Sort Posts:

  • Route impedes delivery of /Content/*

    03-13-2008, 12:22 PM

    I want to have a single controller and action.  I want them both to be by default so they don't clutter the URI.  To that end I have a route like this:

     routes.Add(new Route("{*id}", new MvcRouteHandler())

    {

    Defaults =
    new RouteValueDictionary(new { controller = "Album", action = "Index", id = "" }),

    });

    If I put this route in I find that it MVC will no longer deliver /Content/Site.css.  This can be corrected by changing the route to:

     

    routes.Add(new Route("album/{*id}", new MvcRouteHandler())

    {

    Defaults =
    new RouteValueDictionary(new { controller = "Album", action = "Index", id = "" }),

    });

    But I still can't get to the URI I want i.e. now I have that album thing in there.

     I tried to dig through the code in Reflector but couldn't figure out where this actually happens once it hits UrlRouting.axd...

    Chris
    Filed under:
  • Re: Route impedes delivery of /Content/*

    03-13-2008, 6:10 PM
    • Loading...
    • csainty
    • Joined on 03-12-2008, 2:41 AM
    • Newcastle, Australia
    • Posts 48

    You could look at popping a Constraint onto the Route that says "id does not start with content/"

    Constraints = new RouteValueDictionary(new { id = "<RegExp>" })

    I'll let you work out the correct RegExp, I never was good at doing them off the top of my head.

  • Re: Route impedes delivery of /Content/*

    03-13-2008, 9:07 PM

    I could find very little information on Constraints.  Any pointers?

    Chris
  • Re: Route impedes delivery of /Content/*

    03-13-2008, 10:22 PM
    Answer
    • Loading...
    • csainty
    • Joined on 03-12-2008, 2:41 AM
    • Newcastle, Australia
    • Posts 48

    This should work. 

    routes.Add(new Route("{*id}", new MvcRouteHandler())
    {
    Defaults = new RouteValueDictionary(new { controller = "Album", action = "Index", id = "" }),
    Constraints= new RouteValueDictionary(new { id = "^(?!Content).*" })
    });

    This route should match for any URL that does not start with Content. You might get caught if you have an album name that starts with Content, so maybe Content/ would work better in that expression.

    See how it goes.

  • Re: Route impedes delivery of /Content/*

    03-13-2008, 11:06 PM
    Answer
    • Loading...
    • Haacked
    • Joined on 09-17-2003, 2:43 PM
    • Posts 275
    • AspNetTeam

    You don't need the ^ character. We take what you give us and wrap it like:

    ^(what-you-gave-us)$

     so your constraint on id could be changed to: id="(?!content).*"

     

     

    Phil Haack (http://haacked.com/)
    Senior Program Manager, Microsoft

    What wouldn’t you do for a Klondike bar?
Page 1 of 1 (5 items)