asp.net – 为什么HttpUtility.UrlPathEncode标记为“不使用”?

为什么.NET for HttpUtility.UrlPathEncode for .NET 4.5的文档说明

Do not use; intended only for browser compatibility. Use UrlEncode.

UrlEncode不会这样做,它为URL的参数部分编码字符串,而不是路径部分.有没有更好的方法来编码路径部分的字符串,为什么我不应该使用这个函数,这是在1.1以后的框架中工作?

解决方法

基于 MSDN,他们建议使用UrlEncode来承认它适用于所有平台和浏览器

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.

UrlEncode也使用UTF-8编码,因此如果您使用不同语言(如阿拉伯语)发送查询字符串,则应使用UrlEncode

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...