20140115-URL编码与解码

  1. UrlEncode()方法,有两个类都有这个方法即HttpUtility.UrlEncode和Server.UrlEncode

区别:

1、HttpUtility.UrlEncode,HttpUtility.UrlDecode是静态方法,而Server.UrlEncode,Server.UrlDecode是实例方法。

2、Server是HttpServerUtility类的实例,是System.Web.UI.Page的属性。
3、用HttpUtility.UrlEncode编码后的字符串和用Server.UrlEncode进行编码后的字符串对象不一样 

4、server.urlEncode 可以根据你页面定义好的编码方式进行编码。而 HttpUtility.UrlDecode则默认以utf8来编码。 不然你需要自己指定编码方式:

(ref: http://www.cnblogs.com/akak123/archive/2012/06/13/2547790.html

  1. 作用:对字符串进行 URL 编码,并返回已编码的字符串。

    注:国际通用,防止乱码。与之对应的是UrlDecode操作。

    要编码的内容不一定一定要是URL,更本质上是字符串

  2. 目前在哪里用到了:
    1. 完成文件下载需求时,HttpUtility.UrlEncode
    2. 完成向cookie写数据时,Server.UrlEncode与Server.UrlDecode
原文地址:https://www.cnblogs.com/CharlesZHENG/p/4125075.html