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