Redirect Method (String, Boolean)
.NET Framework Class Library
HttpResponse..::.Redirect Method (String, Boolean)

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 _
)
Visual Basic (Usage)
Dim instance As HttpResponse
Dim url As String
Dim endResponse As Boolean

instance.Redirect(url, endResponse)
C#
public void Redirect(
    string url,
    bool endResponse
)
Visual C++
public:
void Redirect(
    String^ url, 
    bool endResponse
)
JScript
public function Redirect(
    url : String, 
    endResponse : boolean
)

Parameters

url
Type: System..::.String
The location of the target.
endResponse
Type: System..::.Boolean
Indicates whether execution of the current page should terminate.
ExceptionCondition
ArgumentNullException

url is nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentException

url contains a newline character.

HttpException

A redirection is attempted after the HTTP headers have been sent.

ApplicationException

The page request is the result of a callback.

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 throws a ThreadAbortException exception upon completion.

NoteNote:

For mobile pages only, if your application relies on cookieless sessions, or might receive requests from mobile devices that require cookieless sessions, then using a tilde (~) in a path can result in 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 example uses the IsClientConnected property to check whether the client that is 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, then the code calls the End method and all page processing is terminated.

Visual Basic
<%@ 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  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>

C#
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Server.Transfer      Jamie Clayton   |   Edit   |   Show History
According to the article http://msdn.microsoft.com/en-us/library/ms972335.aspx#asptips_topic23 you should use Server.Transfer. See http://msdn.microsoft.com/en-us/library/ms525800.aspx for details on the server tranfer method.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
Page view tracker