Reputation: 2588
Can anyone please let me know the difference between these two?
AntiXss.HtmlEncode()
vs AntiXss.GetSafeHtmlFragment()
Upvotes: 5
Views: 21376
Reputation: 8583
HtmlEcode actually encodes tags:
AntiXss.HtmlEncode("<b>hello</b><script>");
//Output: <b>hello</b><script>
GetSafeHtmlFragment (AntiXss v4.0) returns HTML fragments with tags intact:
Sanitizer.GetSafeHtmlFragment("<b>hello2</b><script>")
//Output: <b>hello2</b>
Many consider the latest version of Microsoft's AntiXSS library broken. I've started using HTML Sanitizer as a decent replacement.
Upvotes: 9
Reputation: 71
It should also be mentioned that antixss.GetSafeHtmlFragment
does encode characters too. A double quote changes to "
. A plus sign turns into +
etc.
Upvotes: 7
Reputation: 51
I would also add that GetSafeHtmlFragment
messes up your CSS, by ading x_ in front of styles, and removes your HTML entity encoding. It is a less than beautiful thing.
Herc
Upvotes: 5