HttpUtility.HtmlDecode ,HttpUtility.HtmlEncode 与 Server.HtmlDecode ,Server.HtmlEncode 与 HttpServerUt

HtmlEncode: 将 Html 源文件中不容许出现的字符进行编码,一般是编码如下字符"<"">""&" 等。

HtmlDecode: 恰好跟 HtmlEncode 相关,解码出来本来的字符。

 

HttpServerUtility 实体类的 HtmlEncode 方法 是一种简便方式,用于在运行时从 ASP.NET Web 应用程序访问 System.Web.HttpUtility.HtmlEncode 方法。HttpServerUtility 实体类的 HtmlEncode 方法 在内部使用 System.Web.HttpUtility.HtmlEncode 对字符串进行编码。

Server.HtmlEncode 其实就是 System.Web.UI.Page 类封装的 HttpServerUtility 实体类的 HtmlEncode 方法; System.Web.UI.Page  类有这样的一个属性: public HttpServerUtility Server { get; }

 

因此咱们能够认为: 
Server.HtmlDecode  =  HttpServerUtility 实体类的 HtmlDecode 方法  = HttpUtility.HtmlDecode ; 
Server.HtmlEncode  =  HttpServerUtility 实体类的 HtmlEncode 方法  = HttpUtility.HtmlEncode  ;

他们只不过是为了调用方便,作了封装而已。
相关文章
相关标签/搜索