Library code snippets
Determine whether a url exists
We've offered you several different solutions for determining whether files
exist. Each one comes with its own particular limitations or ideal-use
conditions. The MSWC.Tools object is a good choice if you're checking for the
existence of a file within the context of your own local root Web site. The
FileSystemObject object, on the other hand, is good for checking for a file
located anywhere on your physical file system (or in shares available to the Web
user). We've also shown you a quick client-side approach for determining whether
image files exist on any Web server, but the technique is intended for the
client computer and applies, for the most part, just to images. Suppose you want
to check for the existence or availability of a Web page on any arbitrary
server. For instance, you might want to create an ASP page of your favorite
links, but you want to make sure, on the server, programmatically, that each one
exists and is currently available before you show it to your end users. The
following code snippet demonstrates how you can use the MSXML library's
ServerXMLHTTP object to carry out this task. Note: You'll need version 3.0 or
later of the MSXML library to use this code.<%
'Timeout values in milliseconds
lngResolveTimeout = 500
lngConnectTimeout = 500
lngSendTimeout = 500
lngReceiveTimeout = 500
strTestUrl = "http://www.microsoft.com/nonexistingpage.html"
Set objHttpRequest = CreateObject("MSXML2.ServerXMLHTTP")
With objHttpRequest
.SetTimeouts lngResolveTimeout, lngConnectTimeout, lngSendTimeout,
lngReceiveTimeout
.Open "GET", strTestUrl
.Send
Select Case .Status
Case 200 'No problem!
Response.Write strTestUrl &
" is a valid, available URL"
Case 404 'Not found
Response.Write strTestUrl &
" could not be found (404 Error)"
Case Else 'Some other problem
Response.Write "An
unexpected HTTP Status value was returned: " &
.Status
End Select
End With
Set objHttpRequest = Nothing
%>
Related articles
Related discussion
-
Header and Footer in Web page print
by fhajaj (4 replies)
-
help me to get simple requirement
by Slicksim (1 replies)
-
Gridview -> Template Field -> Button
by antti.simonen (1 replies)
-
Classic ASP : Page expires
by chezhian_in05 (0 replies)
-
ASP VS PHP
by paulfp (9 replies)
Related podcasts
-
ASP.NET Caching and Performance
Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
Technical Support Engineer EMEA
in Reading (£50K-£50K per annum) -
Solutions Engineer
in Reading (£50K-£60K per annum)
I downloaded the msxml 4 and I think it install, but the code still gave me errors. I wanted to know if I have to declare the variables used in your code.
thanks.
Hi,
I read your question about checking whether url exists using .NET.
Have you found a solution? If you could shard, it would be greate. I am doing the same thing.
Thanks
"You'll need version 3.0 or later of the MSXML library to use this code."
My web server must not have this library. This only works on my home machine. Does anyone know another way?
Hi,
I am using .Net and although I am net getting a timeout exception I am not getting the complete data. I am using a httpwebrequest and setting the timeout value to 500000. Is there anyother way in .Net where I can specify all the these different types of timeouts like recievce timeout, resolve timeout, etc.
Any help and suggestion will be greatly appreciated.
Thank you.
We have our 404.asp designed to fit our site and when you get a 404.asp the url shows the pages you requested but in the body it states that the Page was not found.
So if I run the code you supplied it always states that the url is ok.
Is there a way around this with out chaging the 404.asp page?
This thread is for discussions of Determine whether a url exists.