The manual Page
Version française
     Method Response.Redirect  
[ index | glossary | news | downloads | links ]
 
  introduction to ASP
writting in ASP
ASP variables
the ASP 3.0 objects
the object Request
   .TotalBytes
   .ClientCertificate
   .Cookies
   .Form
   .QueryString
   .ServerVariables
   .BinaryRead
the object Response
   .Status
   .Cookies
   .AddHeader
   .AppendToLog
   .BinaryWrite
   .Clear
   .End
   .Flush
   .Redirect
   .Write
 
news
glossary
downloads
 
guest book
credits
contact
 
 
research
 
last update
25/02/2002
Valid HTML 4.0!
Valid CSS!
Hit-Parade
Measure your audience

Synopsis

Response.Redirect(URL)

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 printable format



Copyright © 2000-2001 themanualpage.org - This site is submissive to the terms of the GNU GPL and FDL licences.