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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....