I am trying to use the following code:
string myString = HttpServerUtility.HtmlEncode("my link & details");
I am getting the following error:
An object reference is required for the nonstatic field, method, or property.
Why can't I use HttpServerUtility.HtmlEncode
inside a class?
You can use HttpUtility
instead, which has a static method that does not depend on HttpContext
.
string myString = HttpUtility.HtmlEncode("my link & details");