I cannot use the HtmlEncoder to encode a string in the asp.net core web API. Can I encode it without using the HtmlEncoder?
1 Answer
I cannot use the HtmlEncoder to encode a string in the asp.net core web API. Can I encode it without using the HtmlEncoder?
To convert a string into an HTML-encoded string, you can use HttpUtility.HtmlEncode method.
var myEncodedString = System.Web.HttpUtility.HtmlEncode(myString);
Besides, if you do not know how to use System.Text.Encodings.Web.HtmlEncoder to encode the supplied string, you can try following code snippet.
var myEncodedString = System.Text.Encodings.Web.HtmlEncoder.Default.Encode(myString);