How do i escape text for html use in C#? I want to do
sample="<span>blah<span>"
and have
<span>blah<span>
show up as plain text instead of blah only with the tags part of the html :(. Using C# not ASP
How do i escape text for html use in C#? I want to do
sample="<span>blah<span>"
and have
<span>blah<span>
show up as plain text instead of blah only with the tags part of the html :(. Using C# not ASP
You can use actual html tags <xmp>
and </xmp>
to output the string as is to show all of the tags in between the xmp tags.
Or you can also use on the server Server.UrlEncode
or HttpUtility.HtmlEncode
.
using System.Web;
var encoded = HttpUtility.HtmlEncode(unencoded);
Also, you can use this if you don't want to use the System.Web assembly:
var encoded = System.Security.SecurityElement.Escape(unencoded)