URL checking

  • Thread starter Thread starter EMW
  • Start date Start date
E

EMW

Hi,

My ASPX (vb.NET) page needs to check an URL.
if it exists then it shows the picture (url is to that picture)
if is doesn't exist, it must show another picture.

but the question is how do I know wheater the URL is valid?

I use a Image webcontrol and that doesn't let me know the picture cannot be
found, it just shows the red x.

rg.
Eric
 
If these images are locale to your machine, you could probably just use the
File.Exist method to determine if that file exists. If these are remote
images, then you will have to use the HttpWebRequest/HttpWebResponse to try
to download the image. If the response is something like a 404, then you
can swap in your substitute image.
 
Using Peter's technique, you could also make a nice site-wide solution using
an HttpModule (or an HttpHandler). There, you would determine if the file
is an image request (.jpg, .jpeg, .gif, .png, .bmp, etc.), and use
System.IO.File.Exist () to determine whether the file is real. If not, you
can Rewrite the Url to point at your placeholder file.

An alternate possibility is to just database the list of photos, and check
there first.

/// M
 
Back
Top