开发者

Properly url encode space character

I use HttpUtility.UrlEncode to encode any value that is used in a route.

I already solved an issue with encoding forward slashes. The new problem I have now is with spaces. A space is encoded as + .

This works on the VS integrated Webserver, but I have an issue with it in IIS7 on Windows Server 2008. If I have the URL http://localhost/Home/About/asdas+sdasd

I get the error 404.1开发者_StackOverflow中文版1 - Request contains double escape sequence.

I know I can just replace the space by "%20", but I dont want to care about propper encoding myself. Is there any ready to use UrlEncoder for MVC out there?


' ' encoded to %20 use HttpUtility.UrlPathEncode.


Any URL Encoding is most often designed to work on the path component of the url, the reason because different schemes have different characters in the safe list. Look for your libraries urlencoder and just use it in the path and above portion of the url.


@HttpUtility.UrlPathEncode(path)

UrlPathEncode just encodes the path of the Url, rather than encoding the whole Url.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜