nathan schmoll's
aspdiscovery

back to main page

e-mail me








How to safely redirect users
OK. You want to redirect a user to some cool web site like http://salttheband.com. You'd probably use this:

<%
response.redirect "http://salttheband.com"
%>

Right? Well you just may be forgetting about those users that are stuck behind proxy servers that don't actually redirect. They just go to a page that says "Object Moved" that has a link to the page you want to redirect to. If it does that, then what's the point of a server-side redirect? Well, there is a safer way to redirect. We just tell the browser that the object has been moved, but to still server-side redirect. If it STILL doesn't want to redirect, we'll stick in a meta tag and some java script to get it to automatically redirect. If the browser doesn't support those methods, we'll at least have a link for the user. Curious?

<%
sub redirect(byval url)
response.buffer=true
response.status="302 Object moved"
response.addheader "Location", url
%>

<html><head><title>Moved Page</title>
<meta http-equiv="refresh" content="0;URL= _
<%=url%>"></head>
<body onload="window.location='<%=url%>'">
This page has been moved. Click
<a href="<%=url%>">here</a> to continue.</body></html>

<%
end sub
%>

Now, whenever you want to redirect somebody, just call the sub "redirect" like this:

<%
redirect "http://salttheband.com"
%>


copyright © 2001, nathan schmoll. all rights reserved. questions? comments? suggestions? e-mail me!