Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public static string SanitizeHtml(this string s)
{
return AntiXss.GetSafeHtmlFragment(s);
}

However, if I pass in a string like this:

black & white


it is encoding the ampersand so it becomes:

black & white

Is there a way of preventing it from encoding this character?
Posted
Updated 12-Oct-16 23:10pm
v2

Why should you...Sanitizing HTML means exactly that...Encode special characters (that can create problems for non-HTML layers in your application) in a way that HTML rendering still will understand, but others will not confused by...
&apm; is something called entity and used widely to ensure correct display of special characters inside HTML without passing those special characters and - maybe - cause troubles...
For instance if you add code block, here at CP, to your question it may contain HTML special characters so the text have to be encoded to ensure correct display...The same way, to prevent XSS attack the content encoded...Why should you not to do that?
 
Share this answer
 
Hello World. This a Cool program. thwere is a chemical element, namely H2O.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900