Verifying a URL

J

julian

Hi,

I have situation where I want to use a stylesheet stored
in one of two possible urls. Basically I need to say if
the first url doesn't exist, use the second url.

I can do this by creating a WebRequest and intercepting
the exception raised by the GetResponse if the first url
doesn't exisit, but this feels like a hack to me and I was
hoping there would be some simple way (similar to
File.Exists) to check whether a url refered to a file that
was actually there?

Any help would be appreciated.

Thanks.
 
M

Mario Vargas

Actually, before I finished reading your post I thought about telling you to
use the WebRequest class. I think you are on the right track, but you might
want to consider caching the URL so that it's not done for every request to
your web form.

Mario
 
J

julian

Thanks for the responses. I guess I will leave it the way
it is then - it certainly works. I just feel a bit
guilty / lazy to be using Exceptions to handle an expected
condition (i.e. not an error).
 
M

Mario Vargas

Actually, that's why structured exception handling was created. You catch an
exception to recover from it. That's how your applications come become
"smarter." They learn from their mistakes, he he.

Mario
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top