-
Hi, I'm trying to detect whether my input contains any forbidden tags. I tried comparing the input with the sanitized output but HtmlSanitizer reformats allowed tags:
Is there another way to check if my input contains any forbidden tags? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The If you can handle an exception in your workflow, something like this might work: sanitizer.RemovingTag += (sender, e) =>
{
throw new ForbiddenTagException(e.Tag);
} where |
Beta Was this translation helpful? Give feedback.
-
Thanks for the response, I figured it out myself eventually: Here's what I used |
Beta Was this translation helpful? Give feedback.
The
RemovingTag
event will be raised anytime a tag is detected which isn't allowed - you can find an example of handling that in the wiki: https://github.com/mganss/HtmlSanitizer/wiki/Examples#ex10-keep-images-audio-and-video-only-from-your-cdnIf you can handle an exception in your workflow, something like this might work:
where
ForbiddenTagException
is a custom exception that accepts anIElement
argument (assuming that you want to log what the tag was at some point).