1

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?

3 Answers 3

1

To be honest, I found the answer here to be more useful: 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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

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 '/'.
0

Exactly what you need(ed)

This is a long time lost shot, but I seem to have exactly what you need. I've written a GreedyRoute class that allows greedy segment anywhere in the URL (at the beginning, in the middle or at the end - which is already supported).

You can read all details on my blog as well as getting the code of this particular class.

The main thing is it supports any of these patterns:

  • {segment}/{segment}/{*segment}
  • {segment}/{*segment}/{segment}
  • {*segment}/{segment}/{segment}

It doesn't support multiple greedy segments though (which is of course possible as well but has some restrictions that should be obeyed in that scenario), but I guess that's a rare example where that could be used.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.