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?
HtmlEncode isn’t a static method, and requires an instance of
HttpServerUtilityto call. Since HttpContext.Current.Server is a HttpServerUtility instance, you can instead use;