How to Html Encode a string in .NET

Html Encoding is basically converting Html tags in non Html tags so that they can be embeded into a html code. Below code explains how rendering of a html string may vary because of html encoding

string htmlString = "<b>Hello world!</b>";

// This will print: Hello world!

string htmlEncoded = Server.HtmlEncode(htmlString);
// This will print: <b>Hello world!</b>

You may want to Html encode a string before showing any user input on the page

6 comment(S)

Ashish nigam on Aug 1, 2008 02:11 AM

How to remove all the tag from a web page and fetch only real data from page .

mksamy on Nov 13, 2008 04:17 AM

Dav on Jan 17, 2010 05:35 AM

You also can use an <a href="http://www.stringfun....html">online html encoder</a>

Dav on Jan 17, 2010 05:37 AM

Sorry to post twice, but my previous post messed up
You also can use an online html encoder ->

satyam on Jun 12, 2012 06:38 AM

i found a useful article written on this topic .....just hv a quick look..might be useful for you

Leave a comment