Properly url encode space character

ⅰ亾dé卋堺 提交于 2019-12-10 12:36:53

问题


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.11 - 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?


回答1:


' ' encoded to %20 use HttpUtility.UrlPathEncode.




回答2:


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.




回答3:


@HttpUtility.UrlPathEncode(path)

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



来源:https://stackoverflow.com/questions/1651711/properly-url-encode-space-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!