且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过特殊字符,所以ASP.NET MVC能够正确处理查询字符串数据?

更新时间:2023-02-15 22:10:54

好吧,我确认这是的现在的在ASP.NET路由一个已知​​的问题,很遗憾。问题是,深路由的深处,我们使用Uri.EscapeString转义开放的路由参数时。然而,这种方法不逃避#字符。

Ok, I confirmed that this is now a known issue in ASP.NET Routing, unfortunately. The problem is that deep in the bowels of routing, we use Uri.EscapeString when escaping routing parameters for the Uri. However, that method does not escape the "#" character.

注意#字符(即井号)在技术上是错误的字符。 C♯的语言其实是一个C,其次是夏普迹象,因为在音乐:http://en.wikipedia.org/wiki/Sharp_(music)

Note that the # character (aka Octothorpe) is technically the wrong character. C♯ the language is actually a "C" followed by a Sharp sign as in music: http://en.wikipedia.org/wiki/Sharp_(music)

如果您使用了锐利的迹象,这可能会解决这个问题。 :P

If you used the sharp sign, that could potentially solve this problem. :P

另一种解决方案,因为大多数人将要使用的井号是写这条路线,并获取虚拟路径路径后,连接code。使用HttpUtility.UrlEn code#号这一个带自定义路由codeS#至23%。

Another solution, since most people will want to use the octothorpe is to write a custom route for this route and after getting the virtual path path, encode the # sign using HttpUtility.UrlEncode which encodes # to %23.

作为后续行动,我想你点这个博客帖子里面谈到过其他非法字符。 http://haacked.com/archive/2010/04/29/allowing-reserved-filenames-in-URLs.aspx

As a follow-up, I wanted to point you to this blog post which talks about passing in other "invalid" characters. http://haacked.com/archive/2010/04/29/allowing-reserved-filenames-in-URLs.aspx