System.Web.HttpUtility VS System.Web.HttpServerUtility VS System.Net.WebUtility

HttpUtility 類做爲 HttpServerUtility 類的內部使用,HttpServerUtility 經過System.Web.UI.Page.Server屬性(WebForm)/Controller.Server(MVC)對外提供服務,他們都位於System.Web命名空間下,供asp.net使用
System.Net.WebUtility提供類似的API,用於非asp.net應用,API內部有細微差異,具體能夠查看.net源碼http://referencesource.microsoft.com
public sealed class HttpServerUtility {
public string HtmlEncode(string s) {
            return HttpUtility.HtmlEncode(s);
        }


public void HtmlEncode(string s, TextWriter output) {
            HttpUtility.HtmlEncode(s, output);
        }

public string HtmlDecode(string s) {
            return HttpUtility.HtmlDecode(s);
        }

public void HtmlDecode(string s, TextWriter output) {
            HttpUtility.HtmlDecode(s, output);
        }


public string UrlEncode(string s) {
            Encoding e = (_context != null) ? _context.Response.ContentEncoding : Encoding.UTF8;
            return HttpUtility.UrlEncode(s, e);
        }

public void UrlEncode(string s, TextWriter output) {
            if (s != null)
                output.Write(UrlEncode(s));
        }
 
public string UrlDecode(string s) {
            Encoding e = (_context != null) ? _context.Request.ContentEncoding : Encoding.UTF8;
            return HttpUtility.UrlDecode(s, e);
        }
public void UrlDecode(string s, TextWriter output) {
            if (s != null)
                output.Write(UrlDecode(s));
        }
}
相關文章
相關標籤/搜索