Redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.
Namespace: System.Web
Assembly: System.Web (in system.web.dll)
Visual Basic (Declaration)
Public Sub Redirect ( _
url As String, _
endResponse As Boolean _
)
Dim instance As HttpResponse
Dim url As String
Dim endResponse As Boolean
instance.Redirect(url, endResponse)
public void Redirect (
string url,
bool endResponse
)
public:
void Redirect (
String^ url,
bool endResponse
)
public void Redirect (
String url,
boolean endResponse
)
public function Redirect (
url : String,
endResponse : boolean
)
Parameters
- url
The target location.
- endResponse
Indicates whether execution of the current page should terminate.
| Exception type | Condition |
|---|
HttpException | A redirection is attempted after the HTTP headers have been sent. |
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.
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" %>
<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>
<head>
</head>
<body>
<form runat="server">
</form>
</body>
</html>
<%@ Page Language="C#" %>
<script runat="server">
private void Page_Load(object sender, EventArgs e)
{
// Check whether the browser remains
// connected to the server.
if (Response.IsClientConnected)
{
// If still connected, redirect
// to another page.
Response.Redirect("Page2CS.aspx", false);
}
else
{
// If the browser is not connected
// stop all response processing.
Response.End();
}
}
</script>
<html>
<head>
</head>
<body>
<form runat="server">
</form>
</body>
</html>
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
.NET Framework
Supported in: 2.0, 1.1, 1.0