1

I need to match this route in my ASP MVC application:

http://localhost/<itemName>/details

When the item name has illegal characters, for example the % symbol, the following URL will blow up:

(1) http://localhost/item%25Name/Details

In this case the correct URL would be:

(2) http://localhost/Details/?item=item%25Name

Is it possible to define routes in RegisterRoutes to match normal routes to (1), and routes with the % symbol in the item name, to (2)?

Thanks in advance

Daniel Peñalba
  • 27,557
  • 31
  • 124
  • 209

1 Answers1

0

Here is what I would recommend you:

  1. For everything that is part of the query string you don't have to worry. It's not necessary to do any special routing.
  2. For everything that goes into the path part of the url you could filter dangerous characters. Here's how this is done on StackOverflow with question titles in the url for example.
Community
  • 1
  • 1
Darin Dimitrov
  • 960,118
  • 257
  • 3,196
  • 2,876
  • Upss, not valid for, me. I need an exact copy of the item name in the server side. The item name is really a file path to search in a Version Control System, so as you can imagine, this must be exact. – Daniel Peñalba May 06 '11 at 08:56
  • @Daniel Peñalba, then I am afraid you will have very hard time using those characters as part of the URL path. In this case probably the query string is the way to go. Avoid using url tokens for variables that can contain such characters as IIS won't give you peace. – Darin Dimitrov May 06 '11 at 08:58
  • The original question, is any way to define routes that match normal routes to (1) and routes with illegal symbols to (2)? – Daniel Peñalba May 06 '11 at 09:04
  • @Daniel Peñalba, no, as if there are illegal symbols IIS will probably drop the request much before it ever had a chance to hit the ASP.NET engine which is running your application. – Darin Dimitrov May 06 '11 at 09:05