Click here to Skip to main content
13,398,199 members (35,649 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 9 Dec 2010

Server.HtmlEncode vs HttpUtility.HtmlEncode

, 19 Dec 2010
Rate this:
Please Sign up or sign in to vote.
Server.HtmlEncode vs HttpUtility.HtmlEncode

Server.HtmlEncode is equivalent to System.Web.HttpContext.Current.Server.HtmlEncode. The Server Object is an instance of the System.Web.HttpServerUtility class and it is readily accessible through any .aspx page since they inherit from the Page object which in turn has a Server Object instance.

The HttpUtility.HtmlEncode function lives under System.Web.HttpUtility. This class is basically a static version of the Server class which means that you could call the HtmlEncode function from a static function or call from another class that does not have an instance of the HttpServerUtility class.

There is a third HtmlEncode function located in the Microsoft’s AntiCross-Site Scripting Library. In contrast with the Server.HtmlEncode and HttpUtility.HtmlEncode functions, the later function takes a more aggressive approach by using a white-list filtering instead of a black-list,hence more PCI standards-compliant, and more secure.

HttpServerUtility.HtmlEncode will use HttpUtility.HtmlEncode internally. There is no specific difference. The reason for existence of Server.HtmlEncode is compatibility with classic ASP.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 5 Nice ! Pin
Dilip Baboo9-Mar-11 14:21
memberDilip Baboo9-Mar-11 14:21 
GeneralReason for my vote of 5 useful for me Pin
lerit_liu19-Dec-10 17:07
memberlerit_liu19-Dec-10 17:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180216.1 | Last Updated 19 Dec 2010
Article Copyright 2010 by Tulika45
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid