URL编码冒号在400 Bad Request中解析

Bri*_*get 5 asp.net urlencode asp.net-mvc-4 asp.net-web-api

为什么这个网址会在400中解决 - 错误请求?

HTTP://本地主机:2785/API /股票/ Web.App.QuotesReaders /搜索= SE%3Aabb

我的环境是Visual Studio 2010,MVC 4和使用的控制器是WebApiController.

%3A是URL编码的冒号.

这有一些原因:

HTTP://本地主机:2785/API /股票的className = Web.App.QuotesReaders&搜索= SE%3Aabb

...这意味着,我无法在global.asax.cs中指定此路由:

/api/ticker/{className}/{search}
Run Code Online (Sandbox Code Playgroud)

......也不是......

/api/ticker/{className}/search={search}
Run Code Online (Sandbox Code Playgroud)

... 但是这个 ...

/api/ticker
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息,请访问:http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx

ang*_*sen 7

似乎ASP.net在'?'之前不允许冒号 在URL中,即使它被编码为%3A.

例如,这些不起作用

http://foo.org/api/persons/foo:bar http://foo.org/api/persons/foo%3abar

但这有效:http: //foo.org/api/persons?id = foo%3abar

在所有示例中,我们希望ASP.NET MVC将"foo:bar"作为id参数传递,并进行正确解码.我刚刚用MVC4对它进行了测试,它似乎有效.令人讨厌的是它不接受问号之前的URL编码,但我确信它有充分的理由.可能要在问号前面保留一切有效的URL和问号后面的任何参数.