11

I am working on an ASP.NET MVC2 project. The problem is when a string which would be rewritten into URL contains a special character such as backslash or question mark, the URL will be wrong, even if I have encoded it before.

For example:

  1. I have a product id "p001\2-2".
  2. I encoded it into "p001%5C2-2"
  3. The URL http://domain.com/Product/p001%5C2-2 responds HTTP Error 400 - Bad Request.

How can I get it correct?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Edison Chuang
  • 2,911
  • 4
  • 26
  • 28
  • I have deleted my answer for now, so question could come up in unanswered section, then some asp.net people can take a look. I supposed to understand url encoding stuff but not asp.net-mvc specific one. – YOU May 20 '10 at 02:18

2 Answers2

6

Try to use Html.Encode to resolve your backslash. If the backslash is the only 'special' character in your id, you could use Replace("%5C","\").

Have you checked your routingMap? there has to be a route like

Product/{prodictID}

Tobi
  • 540
  • 7
  • 18
0

I had a similar problem with %2F in my URLs. Try appending the nOrmalize flag to your rewriteRule.

Example with normalize flag "O" in bold:

RewriteRule ^(.*)index\.html?$ http://www.yoursite.com/$1 [R=301,L,**O**]
Danon
  • 2,771
  • 27
  • 37