How to sanitize Url?

May 17, 2011 at 12:35 PM
Edited May 17, 2011 at 12:35 PM

As explained in
Encoder.UrlEncode we can only use to encode values used in a URL and not the URL itself.

My question is it possible to sanitize Url itself?

E.g. I am loading url of image from DB, and want to prevent any bad code in url before assigning to Image control

. MyImage.ImageUrl=strUrlFromDB;

Please advice.

May 17, 2011 at 5:20 PM

An entire URL? No. You can pick and choose bits by decomposing it using the Uri class, and 4.1 (source only for now) has a UrlPathEncode method, but there's nothing that will simply take a string and encode it as a complete URL.