HttpServerUtility.UrlPathEn code VS HttpServerUtility.UrlEn code [英] HttpServerUtility.UrlPathEncode vs HttpServerUtility.UrlEncode

查看:286
本文介绍了HttpServerUtility.UrlPathEn code VS HttpServerUtility.UrlEn code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么 HttpServerUtility.UrlPathEn code HttpServerUtility.UrlEn code 之间的区别?当我应该选择一个比其他?

What's the difference between HttpServerUtility.UrlPathEncode and HttpServerUtility.UrlEncode? And when should I choose one over the other?

推荐答案

更​​新:为4.5,每MSDN参考,Microsoft建议只使用UrlEn code。另外,在MSDN pviously列出的信息$ P $不完全描述的两种方法中的行为 - 见注释

Update: as of 4.5, per MSDN reference, Microsoft recommends to only use UrlEncode. Also, the information previously listed in MSDN does not fully describe behavior of the two methods - see comments.

所不同的是所有的空间转义 - UrlEn code逃脱他们入+标志,UrlPathEn code释放到%20。 +和%20是仅相当于如果他们每W3C 查询字符串部分的一部分。所以你不能使用+号,只有查询字符串部分逃脱整个URL。底线是,UrlPathEn code始终是更好恕我直言

The difference is all in the space escaping - UrlEncode escapes them into + sign, UrlPathEncode escapes into %20. + and %20 are only equivalent if they are part of QueryString portion per W3C. So you can't escape whole URL using + sign, only querystring portion. Bottom line is that UrlPathEncode is always better imho

您可以连接code与UrlEn code()方法或UrlPathEn code()方法使用的URL。然而,这些方法返回不同的结果。该UrlEn code()方法,每个空格字符转换为加号(+)。该UrlPathEn code()方法将每个空格字符到字符串%20,从而重新presents十六进制的空间。使用UrlPathEn code()方法时,你带code,以保证一致的德codeD URL,无论哪一个平台或浏览器进行解码。该URL的路径部分

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.

<一个href=\"http://msdn.microsoft.com/en-us/library/4fkewx0t.aspx\">http://msdn.microsoft.com/en-us/library/4fkewx0t.aspx

这篇关于HttpServerUtility.UrlPathEn code VS HttpServerUtility.UrlEn code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆