MVC Route URL Patterns

Last post 04-20-2008 12:55 AM by Eilon. 3 replies.

Sort Posts:

  • MVC Route URL Patterns

    04-09-2008, 6:39 AM
    • Loading...
    • Peter Meir
    • Joined on 04-09-2008, 10:27 AM
    • Belgium
    • Posts 8

    Hi,

    I was wondering what the different urlpatterns are that can be used. So far I know that a variable can only come after or before a '/'.

    These are correct : 

    /test/{category}
    /test/{category}.html

    This is however wrong and is not being routed :

    /test/test{category}.html

    I need a way of getting the above url to route from a page like http://localhost/test/testapples.html into an aspx page with 'category' as an item in RouteData.Values.

    So far I have been using MVC as an alternative to URL Rewriting but this is something I need to complete my tests and start implementation.
    All I have so far comes from Haack's demo which is on his nice blogpost here : http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx

    Thanks in advance!

    Peter 

    Don't forget to click "Mark as Answer" on the post(s) that helped you. This credits that member, earns you a point and marks your thread as Resolved.
    Pinky: Hmmm... let me think...
    Brain: Don't hurt yourself, Pinky.
    Filed under: , , ,
  • Re: MVC Route URL Patterns

    04-09-2008, 8:29 AM
    Answer
    • Loading...
    • paul.vencill
    • Joined on 02-01-2006, 12:57 PM
    • Gaithersburg, MD
    • Posts 683

    Right now, they just split on the / as you said. This guy: http://www.iridescence.no/Posts/Defining-Routes-using-Regular-Expressions-in-ASPNET-MVC.aspx built a regex-based route parser that you might try; and I've heard that the ASP.Net MVC team is considering adding a regex based route parser as an alternative; might be wrong on that one, though.

  • Re: MVC Route URL Patterns

    04-09-2008, 8:52 AM
    • Loading...
    • Peter Meir
    • Joined on 04-09-2008, 10:27 AM
    • Belgium
    • Posts 8

    Hi,

    Thanks for your quick reply!
    This is exactly what I was looking for!
    I read about regex implementation too just now, and the same guy made a post about outbound url's when using regular expressions :
    http://www.iridescence.no/Posts/Outbound-Urls-with-Regular-Expression-Routes.aspx

    He thinks this is the reason that the Microsoft MVC team won't implement this yet.
    I don't use outbound url's anyway, I am just looking for an alternative to url rewriting.

    Regards,
    Peter
     

    Don't forget to click "Mark as Answer" on the post(s) that helped you. This credits that member, earns you a point and marks your thread as Resolved.
    Pinky: Hmmm... let me think...
    Brain: Don't hurt yourself, Pinky.
  • Re: MVC Route URL Patterns

    04-20-2008, 12:55 AM
    Answer
    • Loading...
    • Eilon
    • Joined on 06-26-2002, 6:14 PM
    • Redmond, WA
    • Posts 747
    • AspNetTeam

    FYI the latest version of the routing system in MVC that you can download support splitting on any character, not just a "/" character. The original route you showed should now be supported.

    Thanks,

    Eilon

    Blog: http://weblogs.asp.net/LeftSlipper/
Page 1 of 1 (4 items)
Microsoft Communities
Page view counter