Monthly Archives: October 2007

UrlEncode vs. HtmlEncode

The difference between these two commands is obscure, and plagued me for some time.  It just gelled in my head, so I thought I’d share.

HtmlEncode — makes it safe to display user-entered text on a web page.  ‘<‘ and ‘>’ are turned into &lt; and %gt;

UrlEncode — makes it safe to work as a url.  ‘ ‘ is turned into ‘+’ and a bunch more.

Well, which to use in an HTTP POST?  The magic bullet comes from http://aspnetresources.com/blog/encoding_forms.aspx

“If you’re wondering which one you should use in an HTTP POST, well just think of POST data as an extremely long query string. So naturally you will need to use UrlEncode.”

Simple as that…  Once again, wish I had thought of that