Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect invalid URL 2

Status
Not open for further replies.

avu

Technical User
Aug 8, 2003
53
0
0
CA
Hi, could someone please advice how I can use VBScript to redirect to another link if the original link is invalid?

Here's my issue:
<a href="detect_link.asp">GO LINK</a>

at "detect_link.asp", I need to have script to detect if the URL is accessible (
if the secured site is not accessible (perhaps 404), the script would then redirect me to another URL.

I tried to used WScript.Shell to ping the secured URL, but that wouldn't work.

Please help! Thanks in advance.

- Allan
 
I cannot think of a way to accomplish this directly from the calling page. Is the page you're trying to detect a page under your control? If so, I suspect you're going to have to code something into that page indicating that redirects have found their mark.

------------------------------------------------------------------------------------------------------------------------
"As for the bureacratic, politically-correct, mollycoddling, asinine, Romper Room antics of...clients and management, just read up on Dilbert. It's not funny - it's a training manual."
- Mike
 
If these links are on your ASP page maybe use the XMLHTTP object to check if the page is available. Unless you expect these links to go bad on a regular basis, it might be better to do this weekly as a scheduled task.
 
Hi Chopstik,
I have control of detect_link.asp but not the pages under the secured site. Could you please give an example of the code you referred to?

Hi Sheco,
Would you please care to explain more?

Here's the code I currently have on the detect_link.asp page:

<% Response.Buffer = true %>
<%
url = "some.secured.site.com"

Set objWShell = CreateObject("WScript.Shell")
Set objCmd = objWShell.Exec("ping " & url)
strPResult = objCmd.StdOut.Readall()
set objCmd = nothing: Set objWShell = nothing

strStatus = "offline"
if InStr(strPResult,"TTL=")>0 then strStatus = "online"

if (strStatus = "online") then
response.redirect url
else
response.redirect " end if

' response.write url & " is " & strStatus
' response.write ".<br>" & replace(strPResult,vbCrLf,"<br>")
%>

The problem with this code is "some.secured.site.com" always returns 'offline', although it's actually online. It'd work if I try a non-https site.
Any suggestions?

Thanks again.
 
Just to clarify what I'm try to do, I need to provide a link to online webmail to users. The problem is the main secured webmail site is sometime down, so I need to detect this and if that's the case, redirect users to an alternate webmail site.

So, the sample link is:
<a href="detect_link.asp">Webmail</a>

On "detect_link.asp", the vb code will try to detect if the main secured site is accessible ( if not, redirect to the alternate site (
Thanks for your help.
 
4 Guys From Rolla has an example of something that I suspect may be of use to you. I've never really used the XMLHTTP object that sheco referred to but it appears to be the best option for what you need. Nice call, sheco. A star for you...

------------------------------------------------------------------------------------------------------------------------
"As for the bureacratic, politically-correct, mollycoddling, asinine, Romper Room antics of...clients and management, just read up on Dilbert. It's not funny - it's a training manual."
- Mike
 
Hi Chopstik,
Unfortunately it's not quite working. I got the error as described here.

I don't have access to server so guess I'm outta luck. A star for you anyway.

Thanks again.
 
There is more than one version of the XML parser that can be used to do this trick... perhaps your web hosting company supports another one? Doesn't hurt to ask!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top