Meesam Abbas
Meesam Abbas

Reputation: 126

How to render invalid HTML tags as text alongside valid HTML tags?

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

Answers (1)

Travis J
Travis J

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 &lt;test&gt; as opposed to <test>. The ampersand values will render as < text on the page.

Upvotes: 1

Related Questions