Is this route possible

Last post 03-30-2008 12:55 PM by tgmdbm. 4 replies.

Sort Posts:

  • Is this route possible

    03-29-2008, 3:51 PM
    • Loading...
    • srulyt
    • Joined on 02-02-2008, 6:16 PM
    • Posts 208

    I want to make a route that could ckeck the end of the url for a pattern and if matched pass the entire url to the action as the parameter.

    The point of this is to catch things like /something/something/robots.txt or something/something/sitemap.xml an than pass the url to an action that generates the the robots.txt or sitemap

     I did this with my own url forwarding handler in a webforms app by checking the end of the url before passing it to the regular routing handlers.

    the rout "{*catchall}/robots.txt" doesn't work because a catchall can only be at the end of the pattern.

    How can i get this done using MVC routing

     Thanks

    Filed under:
  • Re: Is this route possible

    03-29-2008, 4:45 PM
    Answer
    • Loading...
    • tgmdbm
    • Joined on 12-17-2007, 9:08 AM
    • Posts 584
    • ASPInsiders

    Url = "{*catchall}"
    Contraints = new RouteValueDictionary{ { "catchall", ".*/robots\.txt" } } 

  • Re: Is this route possible

    03-29-2008, 4:49 PM
    • Loading...
    • ChanceUSC
    • Joined on 07-18-2007, 11:14 PM
    • Posts 183

     What you would do is use {*catchall} and then split the catchall by tokenizing it as "/" your delimiter. You'd then store all of those tokens into an array, check the last one for robots.txt or whatever else you  plan on looking for. As far as the sitemap goes though, I'm not sure how useful this would be, because if I'm not mistaken - Google caches their sitemaps. Although, if you generate it you could also use ajax to force an update on it through all of the search engines...
     

    Chance 

  • Re: Is this route possible

    03-30-2008, 12:32 PM
    • Loading...
    • srulyt
    • Joined on 02-02-2008, 6:16 PM
    • Posts 208

    tgmdbm:

    Url = "{*catchall}"
    Contraints = new RouteValueDictionary{ { "catchall", ".*/robots\.txt" } } 

    thanks, can you give some more info on constraints, how to create them and how they work

  • Re: Is this route possible

    03-30-2008, 12:55 PM
    • Loading...
    • tgmdbm
    • Joined on 12-17-2007, 9:08 AM
    • Posts 584
    • ASPInsiders

     http://www.regular-expressions.info/

Page 1 of 1 (5 items)