Reputation: 126
I have an HTML string in my code behind which has some valid html tags such as <br/>
, <p></p>
, and some invalid tags such as <test>
. I want to render both sets of tags in the browser in such a way that invalid tags are rendered as plain text.
For example, the string
<test><br/>hi mark.<br/>how are you.My email is <[email protected]>
would to need to output on the browser as
<test>
hi mark.how are you.My email is <[email protected]>
Upvotes: 2
Views: 272
Reputation: 82297
You would need to whitelist the elements you consider to be valid, and then encode those which do not match the whitelist so that they are instead converted to <test>
as opposed to <test>
. The ampersand values will render as <
text on the page.
Upvotes: 1