Active Server Pages
ASP Redirection
Grizzly WebMaster home
 Grizzly WebMaster (HOME) >> Server Development >> ASP Redirection
See Also
"Page Redirection - JavaScript" for more techniques of redirecting from one page to another.
This Active Server Page demonstrates a good method for redirecting your visitor to a different page.

Before any <html> tag we simply identify the target page and then call "Response.Redirect" to change to the requested page.  For most browsers that is all that is required.

Save Source
Right mouse button here and select "save target as" to save the source.  Note that you will be download a "txt" file which must be renamed.

Some older browsers do not correctly handle server requested redirection.  As a result we follow the "Response.Redirect" with our standard redirection JavaScript.  See our "Page Redirection - JavaScript" for an explanation of the JavaScript.

Obviously before using these functions you would want to remove the verbose comments.

See this script in action.


<%
DIM sTarget

sTarget = "../../javascripts/examples/redirectiontarget.htm"
Response.Redirect sTarget

'   You might ask, why should we have anything else?
'
'   Some browsers (especially older browsers) do not
'   correctly handle the server requesting the browser
'   to redirect to another page.
'
'   As a result we include our standard redirection
'   javascript page.  The only difference is that we
'   use the ASP variable substitution to provide the
'   redirection target.
'
'   Browsers that correctly handle server directed
'   redirection will never see the html that follows
'   in this file.
%>
<html>

<head>
<title>Redirection ASP Example</title>
<noscript>
<!--
    Note that we are using variable substitution to
    identify the refresh target.
-->
<meta http-equiv="refresh" content="2; URL=<%=sTarget%>">
</noscript>
<script language="JavaScript">
<!--

//  This is a strange looking assignment.  We are using
//  the ASP variable and variable substitution to provide
//  the JavaScript target URL.
//
var sTargetURL = "<%=sTarget%>";

function doRedirect()
{
    setTimeout( "window.location.href = sTargetURL", 2*1000 );
}

//-->
</script>

<script language="JavaScript1.1">
<!--
function doRedirect()
{
    window.location.replace( sTargetURL );
}

doRedirect();

//-->
</script>

</head>

<body onload="doRedirect()">

<p>Loading <a href="<%=sTarget%>">redirection target</a></p>
<p>The redirection target page should load in a couple of seconds.<br>
If it doesn't please select the link above.</p>

</body>

</html>
Service Provided by Bear Consulting Group Last modified: 25 May 2009
Copyright 2001 Bear Consulting Group