Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between HttpUtility.HtmlEncode and Server.HtmlEncode

Tags:

c#

asp.net

What is the difference between HttpUtility.HtmlEncode and Server.HTMLEncode?

like image 355
GibboK Avatar asked Dec 07 '10 07:12

GibboK


People also ask

What is Server HtmlEncode?

The HTMLEncode method applies HTML encoding to a specified string. This is useful as a quick method of encoding form data and other client request data before using it in your Web application. Encoding data converts potentially unsafe characters to their HTML-encoded equivalent.

What does HttpUtility HtmlEncode do?

This is a useful class. It provides methods (HtmlEncode and HtmlDecode) that manipulate HTML strings. Other methods support URL encoding.


1 Answers

Have a look at Server.HtmlEncode vs HttpUtility.HtmlEncode .

Basically, Server.HtmlEncode uses a specific instance of the System.Web.HttpServerUtility class that's inherited from the Page class. HttpUtility.HtmlEncode is a static method, so you don't have to instantiate the HttpUtility class.

All else being equal, go with the static HttpUtility.HtmlEncode.

like image 169
Adriaan Stander Avatar answered Oct 09 '22 07:10

Adriaan Stander