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

detecting 404 errors

Status
Not open for further replies.

ozpeppers

Programmer
Jul 17, 2001
32
BN
Hello,

I'm building a web portal that users can submit their sites to.

These sites are linked to.. at moment using repsonse.redirect(address)

Does anyone know of a way to detect a 404 or similar error and redirect the page back to the portal, so site can be flagged as having an error.

Thanks in advance

Mark
 
Are you using IIS? If so you can look at the properties of your web site & go to the Custom Errors tab. Haven't tried it, but this may do what you want.

Jessica [ponytails2]
 
I assume you don't control the sites you are redirecting to?

How about using the M$ XMLHTTP object?

Here's a simple little example of it in action (sorry but it's in my preferred ASP language, Javascript).

<%@language=&quot;javascript&quot; enablesessionstate=&quot;false&quot;%>
<%
var url = new String(Request.QueryString(&quot;URL&quot;));
var startmarker = new String(Request.QueryString(&quot;start&quot;));
var stopmarker= new String(Request.QueryString(&quot;stop&quot;));
var avoiddomain= new String(Request.QueryString(&quot;avoiddomain&quot;));
var trimstop= new String(Request.QueryString(&quot;trimstop&quot;));
if (isNaN(trimstop)) trimstop = 0;
if (url != &quot;undefined&quot;){
url = &quot; + url.replace(&quot; &quot;&quot;)
var http = Server.CreateObject(&quot;Microsoft.XMLHTTP&quot;);
http.open(&quot;GET&quot;, url, false);
http.setRequestHeader(&quot;Content-type:&quot;, &quot;text/html&quot;);
try{
http.send();
if (http.statusText == &quot;OK&quot;){
var output = new String(http.responseText);
if (output != &quot;undefined&quot; && startmarker != &quot;undefined&quot;)
output = output.substring(output.indexOf(startmarker), output.length);
if (output != &quot;undefined&quot; && stopmarker != &quot;undefined&quot;)
output = output.substring(0, output.indexOf(stopmarker) + stopmarker.length * (1 - trimstop));
output = output.replace(/http:\/\//gi, &quot; if (output != &quot;undefined&quot; && avoiddomain != &quot;undefined&quot;)
var avoiddomainre = new RegExp(&quot;href=\&quot;.*&quot; + avoiddomain + &quot;.*\&quot;&quot;, &quot;gi&quot;);
output = output.replace(avoiddomainre, &quot;name=\&quot;\&quot;&quot;);
if (output != &quot;undefined&quot;) Response.write(output);
}
}catch(e){
%><html>
<body>
<% Response.write(e);
%> </body>
</html>
<% }
http = null;
}
%>

This doesn't quite do what you want, but with minor modifications it could (note in particular the statusText property above).



codestorm
Fire bad. Tree pretty. - Buffy
Kludges are like lies.
You're not a complete programmer unless you know how to guess.
I hope I never consider myself an 'expert'.
<insert witticism here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top