HttpResponse.Redirect Method (String, Boolean)
Assembly: System.Web (in system.web.dll)
'Declaration Public Sub Redirect ( _ url As String, _ endResponse As Boolean _ ) 'Usage Dim instance As HttpResponse Dim url As String Dim endResponse As Boolean instance.Redirect(url, endResponse)
public void Redirect ( String url, boolean endResponse )
public function Redirect ( url : String, endResponse : boolean )
Not applicable.
Parameters
- url
The target location.
- endResponse
Indicates whether execution of the current page should terminate.
An absolute URL (for example, http://www.contoso.com/default.aspx) or a relative URL (for example, default.aspx) can be specified for the target location but some browsers may reject a relative URL.
Redirect calls End which raises a ThreadAbortException exception upon completion.
Note: |
|---|
| For mobile pages only, if your application relies on cookieless sessions, or might receive requests from mobile devices that require cookieless sessions, using a tilde ("~") in a path can result in inadvertently creating a new session and potentially losing session data. To set a property on a mobile control with a path such as "~/path", resolve the path using ResolveUrl "~/path" before assigning it to the property. |
The following code example uses the IsClientConnected property to check whether the client requesting the page remains connected to the server. If IsClientConnected is true, the code calls the Redirect method, and the client will view another page. If IsClientConnected is false, the code calls the End method and all page processing is terminated.
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Private Sub Page_Load(sender As Object, e As EventArgs) ' Check whether the browser remains ' connected to the server. If (Response.IsClientConnected) Then ' If still connected, redirect ' to another page. Response.Redirect("Page2VB.aspx", false) Else ' If the browser is not connected ' stop all response processing. Response.End() End If End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>ASP.NET Example</title> </head> <body> <form id="form1" runat="server"> </form> </body> </html>
Note: