0

I have seen this post: MVC Handler for an unknown number of optional parameters but it's for MVC and doesn't seem to work for me as I get an error:

A path segment that contains more than one section, such as a literal section or a parameter, cannot contain a catch-all parameter.

I want to be able to have an indeterminate amount of params in a Url, I have the following route:

RouteCollection.MapPageRoute("ManyParam", "{*params}.html", "~/Default.aspx");

This also seems to trigger the error message above.

How can I set up a route to have an unknown number of parameters in web forms (not MVC).

I am trying to achieve the following urls:

www.example.com/some-thing.html
www.example.com/some-thing/else.html
www.example.com/and/some-thing/else.html
www.example.com/1/2/3/4/5/6.html

EDIT

It seems to work when I use the following:

RouteCollection.MapPageRoute("ManyParam", "{*params}", "~/Default.aspx");

The problem is with this is that it doesn't allow the .html at the end.

Community
  • 1
  • 1
webnoob
  • 15,747
  • 13
  • 83
  • 165
  • Can you show how your desired Url look like? Your `"{*params}.html"` does not make it very clear what you want to achieve... – Alexei Levenkov Aug 28 '13 at 07:19
  • @AlexeiLevenkov - That would of been useful ... Added, thanks. – webnoob Aug 28 '13 at 07:33
  • Try `"{*path}"` for Url and have some sort of [constraint](http://www.asp.net/mvc/tutorials/controllers-and-routing/creating-a-route-constraint-cs) that will require `.html` at the end using 5 arguments override of [MapPageRoute](http://msdn.microsoft.com/en-us/library/dd992978.aspx) – Alexei Levenkov Aug 28 '13 at 07:37
  • @AlexeiLevenkov - I have tried that: `RouteCollection.MapPageRoute("ManyParam", "{*path}.html", "~/Default.aspx");` but I get the error: `A path segment that contains more than one section, such as a literal section or a parameter, cannot contain a catch-all parameter.` Am I doing something wrong with the `.html` at the end? – webnoob Aug 28 '13 at 07:40
  • I tried to add rough sample as answer... – Alexei Levenkov Aug 28 '13 at 07:45

1 Answers1

1

Untested route below - the wildcard one have to be absolutely last portion of Url. So to force ".html" at the end you need to use constraint (5th argument).

routes.MapPageRoute(
    "ManyParam",
    "{*path}",
    "~/Default.aspx",
    false,
    new RouteValueDictionary(),
    new RouteValueDictionary { { "path", @".*\.html" } }
 );
webnoob
  • 15,747
  • 13
  • 83
  • 165
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • Isn't that MVC though? I don't have a controller. – webnoob Aug 28 '13 at 07:45
  • @webnoob - edited to probably be more correct - the point is you have to use constraint since you can't have anything past wildcard segment. – Alexei Levenkov Aug 28 '13 at 07:50
  • Right Ok, that falls in line with my tests I have been running. I will look up constraints with web forms and see what I can do. Thanks for your time. – webnoob Aug 28 '13 at 07:51
  • Works perfectly (with a slight tweak to the syntax). Many thanks again for your time. – webnoob Aug 28 '13 at 08:18