ASP 302 redirection (temporary redirection)

Script version:1.0
Language:ASP
Rating:
8 (2 votes cast)
Category:HTTP Status Codes
Description:How to do a temporary redirection in ASP. Note, If you are redirecting to another page on a permanent basis, it is recommended that you use a 301 redirect rather than a 302 redirect because Google will allocate any link weighting towards page rank to the new page if you use a 301 redirect, but if you use a 302 redirect, then this page ranking is effectively.
Instructions:copy the code to the head of your page. Note, in some circumstances, you may want to implement the redirection based on certain conditions, for example, if you are writing a script for logging into a website and want to redirect to different pages depending on the result of the recordset query, you need to ensure that you do not redirect the page before closing all objects, for example, the following code is wrong:

<%
' do not use this code - it will cause a memory leak!!
userpass = request("userpass")
if userpass <> "" then
SQL = "select top 1 * from users where user_password='" & replace(userpass,"'","''") & "'"
set conn = "[insert connection string]"
set rs = conn.execute(SQL) '
if rs.eof then
response.redirect "notfound.asp"
else
response.redirect "loggedin.asp"
end if
set rs = nothing
conn.close
set conn = nothing
else
response.redirect "notfound.asp"
end if
%>

Instead you should do the redirect after closing the objects like this:

<%
' use this code instead
redirectURL= "notfound.asp"
userpass = request("userpass")
if userpass <> "" then
SQL = "select top 1 * from users where user_password='" & replace(userpass,"'","''") & "'"
set conn = "[insert connection string]"
set rs = conn.execute(SQL) '
if not rs.eof then
redirectURL="loggedin"
end if
set rs = nothing
conn.close
set conn = nothing
end if
response.redirect redirectURL
%>
Code:




Comments

Name: *
Email: (not shown on website)
Website:
Rate this script:
1 2 3 4 5 6 7 8 9 10
worse better
Comment: *
CAPTCHA Image
Change Image
Write the characters in the image above


* = required field

Related Scripts:

ASP 301 permanent redirection

ASP Add date modified header

Tags

[ http ] [ redirection ] [View tag cloud]

Back to main scripts page








Tag Cloud    Submit a script


Latest Scripts Added

jQuery image swap on mouseover (jQuery)
04 January 2012
This simple bit of code allows you to quickly create image rollovers. The code was modified from a version by Sam Colletts on http://webdevel.blogspot.com/2008/04/rollover-images-with-jquery.html ...

replace XML characters in a string using ASP.Net (ASP.Net)
12 December 2011
Sometimes you need to insert a string into an xml document. Before doing this, you need to ensure that your string does not contain any special xml characters. It is possible to use a CDATA section ...

How to remove title tag in ASP.Net (ASP.Net)
14 October 2011
This is not really a script, but a little trick that you can use to remove the title tag in ASP.net. In ASP.net, when the head tag is rendered, the title tag is automatically added. One of the real ...

ASP sort numerical array (ASP)
12 September 2011
This code is similar to the sort array script which sorts an array alphabetical, however it also sorts arrays based on numberical ordering, for example: dim numbers(4) numbers(0) = ...

Force file download in ASP.Net / c# (ASP.Net)
02 September 2011
this script allows you to force browsers to display a file save dialogue for any file type. It contains a string of allowed file types so users cannot change the querystring to downoad your ...