Using redirects in ASP scripts is a very convenient way to send users to
appropriate pages, especially where the destination page is based on some
condition. Consider the following script <%
'determine destination based on success of login
If session("login_authenicated") then
'valid user
Response.Redirect("mainmenu.asp")
Else
'invalid user
Response.Redirect("login.asp")
End If
%>
This code works well in theory, but generates one of the most common
ASP error messages when pasted into your scripts, which looks something
along the lines of:
Response object error 'ASP 0156 : 80004005'
Header Error
Some.asp, line ##
The HTTP headers are already written to the client browser.
Any HTTP header modifications must be made before writing page content.
The solution is simple, but often unmentioned in example code. A
condition of using redirects in ASP script is the existence of the
statement:
<%Response.buffer = True%>
before the <HTML> tag. A typical redirect script should therefore begin:
<%Response.buffer = True%>
<HTML>
<HEAD>
<%
'determine destination based on success of login
If session("login_authenicated") then
'valid user
Response.Redirect("mainmenu.asp")
Else
'invalid user
Response.Redirect("login.asp")
End If
%>
</HEAD>
|