HtmlEncode(String) 将字符串转换为 HTML 编码字符串。html
HtmlDecode(String) 将已经为 HTTP 传输进行过 HTML 编码的字符串转换为已解码的字符串。web
在web端项目中一般使用HttpUtility.HtmlEecode,HttpUtility.HtmlDecode,Server.HtmlEncode,Server.HtmlDecode;api
在C端项目中一般使用WebUtility.HtmlEncode,WebUtility.HtmlDecode;asp.net
在说HttpUtility.HtmlEecode,HttpUtility.HtmlDecode,Server.HtmlEncode,Server.HtmlDecode这几个以前呢,得先说下HttpServerUtility类。函数
提供用于处理 Web 请求的 Helper 方法。工具
html编码相关的方法以下:编码
这个类没有构造函数,因此不能直接new出来一个实例;spa
但三种种状况会返回这个类的实例。.net
提供在处理 Web 请求时用于编码和解码 URL 的方法。 此类不能被继承。3d
HttpUtility类在内部使用HttpServerUtility类,其方法和属性经过内部 ASP.NETServer对象对外公开。 此外,HttpUtility类包含编码和解码实用工具方法,当不能访问Server时,能够使用它。
该类在web项目中均可以使用:
在C端项目中使用System.Net.WebUtility类进行Html编解码:WebUtility.HtmlEncode,WebUtility.HtmlDecode
http://www.javashuo.com/article/p-huzaroxe-mm.html