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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trapping Response.Redirect error

Status
Not open for further replies.

luzmedia

Programmer
Mar 25, 2002
7
0
0
FR
How can I trap the error created when Response.Redirect tries to redirect to a non-existent - or unavailable - URL? I've tried On Error Resume Next but the script still falls over if the URL is no good.

I have to be able to do this with straightforward ASP and, in particular, without using XMLHTTP.

Here's what I want to be able to do:

--------------------------
target_url = "
If THIS_URL_EXISTS_AND_IS_AVAILABLE_RIGHT_NOW("target_url") Then

Response.Redirect target_url

Else

Response.Write target_url & " is not available"

End If
-------------------------------

So what I need is a definition for THIS_URL_EXISTS_AND_IS_AVAILABLE_RIGHT_NOW(url)

I'd be very grateful for any solutions.
Cheers
Charlie
 
Try Server.Execute(aspPageInSameApp) and trapping that.

HTH,
Elijah
 

I did a little testing and found this sort-of solution:
Code:
:: dir/file1.asp ::

<%
  On Error Resume Next ' Plenty of trapping options, though
  Server.Execute(&quot;file2.asp&quot;)
%>

:: dir/file2.asp ::

<%
  If Request.ServerVariables(&quot;URL&quot;) <> &quot;/dir/file2.asp&quot; Then _
  Response.Redirect(&quot;file2.asp&quot;)
%>

This way, you could trap the error, and if the page is available, it will redirect straight to it instead of having one page inside another (which is what will happen with Server.Execute)

HTH too,
Elijah
 
Hi Elijah
Sounds like a good solution, but it doesn't work when the target url is on another server.

I tried this:
file master.asp
---------------
<%
On Error Resume Next
Server.Execute &quot;slave.asp&quot;
Response.Write &quot;slave failed so we are still in master&quot;
%>

file slave.asp
--------------
<%
Response.Redirect &quot;%>

I hoped when the Server.Execute failed I'd get &quot;slave failed so we are still in master&quot;, but I still got the &quot;Page cannot be displayed&quot; error from the failed Response.Redirect

Back to the drawing board...

Cheers
Charlie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top