Synopsis
This method will make the Web browser look for another resource. For example, we use this method to redirect the Web browser to
a page, according to the authentication ID the client has provided. Once this method is called, the script processing is stopped.
This method send a specific HTTP header to the client (Location:) in the response header. Therefore, it allow to use
this method if and only if the headers have not been sent already. In concrete terms, it is not possible to use the method
Request.Redirect as soon as an HTML tag has been written. In order to control this latter behavior, it adviced to use
the output buffer and the method Response.Clear (see the example below).
URL is mandatory; this URL is the resource to which we want to redirect the client.
Example
In the following example, we are going to test the value of a login one has sent to the server. If the login equals "foo", we
display a success message, otherwise, we redirect the browser to the initial file and provide a error message:
|
form.asp:
...
<%
If Request.QueryString("error") <> "" Then
Response.Write("<P>bad login</P>")
End If
%>
<FORM action="test.asp" method="GET">
<INPUT type="text" name="login">
<INPUT type="submit" value="send">
</FORM>
...
test.asp:
<%
' We activate the output buffer
Response.Buffer = True
%>
<HTML>
<BODY>
<%
If Request.QueryString("login") = "foo" Then
Response.Write("Congratulations!!")
Else
' We redirect to form.asp. As some HTML tags have already been
' written, we must clear the buffer before calling Redirect
Response.Clear
Response.Redirect("form.asp?error=true")
End If
%>
</BODY>
</HTML>
|
printable format
|