开发者

Illegal character % in ASP MVC route

I need to match th开发者_开发百科is 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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜