12

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

Alexei Levenkov
  • 96,782
  • 12
  • 124
  • 169
GibboK
  • 68,054
  • 134
  • 405
  • 638

1 Answers1

14

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.

Alexei Levenkov
  • 96,782
  • 12
  • 124
  • 169
Adriaan Stander
  • 156,697
  • 29
  • 278
  • 282