微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net – HttpServerUtility.UrlPathEncode vs HttpServerUtility.UrlEncode

HttpServerUtility.UrlPathEncode和HttpServerUtility.UrlEncode有什么区别?何时应该选择一个呢?

解决方法

更新:从4.5开始,根据MSDN参考,Microsoft建议仅使用UrlEncode。此外,以前在MSDN中列出的信息并没有完全描述两种方法的行为 – 请参阅注释。

区别在于所有的空间转义 – UrlEncode将它们转义为符号,UrlPathEncode转义为。并且仅当它们是QueryString部分per W3C的一部分时才是等效的。因此,您不能使用符号,只有querystring部分来转义整个URL。 UrlPathEncode总是更好的imho

You can encode a URL using with the UrlEncode() method or the UrlPathEncode() method. However,the methods return different results. The UrlEncode() method converts each space character to a plus character (+). The UrlPathEncode() method converts each space character into the string “%20”,which represents a space in hexadecimal notation. Use the UrlPathEncode() method when you encode the path portion of a URL in order to guarantee a consistent decoded URL,regardless of which platform or browser performs the decoding.

07001

原文地址:https://www.jb51.cc/aspnet/253149.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐