views:

106

answers:

3

I am trying to write a route that matches the following URL format:

/category1/category2/S/

where the number of categories is unknown, so there could be 1 category or there could be 10 (1..N).

I cannot use a catch all becuase the categories are not at the end of the URL.

I am actually routing to a web form here (using Phil Haack's example http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx), but that is beside the point really.

Any ideas?

A: 

I think it's impossible but you could try work around it using this route:

{categories}/S

Then split the categories using the '/' character yourself.

I made a site where I just fixed it to 1-3 categories by registering 3 routes, but I had to work around a lot of things and wasn't really happy with it afterwards.

EDIT: Using S/{*categories} will catch the categories. You can only use it at the end of the URL.

Marcel Wijnands
I did actually try the {categories}/S route, but it doesn't match. If I use a different delimiter betweeen the categories (e.g. a dash: /category1-category2/S/) then it seems to work fine. Trouble is I cannot change the delimeter, I have to use the '/'.
DownChapel
+1  A: 

Here's my own question about the same thing and the answers:

http://stackoverflow.com/questions/1332782/asp-net-unknown-length-mvc-paths

Palantir
+1  A: 

To be honest, I found the answer here to be more useful: http://stackoverflow.com/questions/301230/using-the-greedy-route-parameter-in-the-middle-of-a-route-definition

The blog post linked to in the question was extremely useful: http://www.thecodejunkie.com/2008/11/supporting-complex-route-patterns-with.html

DownChapel