Redirect Method (String, Boolean)
Collapse the table of content
Expand the table of content

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)

public void Redirect(
	string url,
	bool endResponse


Type: System.String

The location of the target.

Type: System.Boolean

Indicates whether execution of the current page should terminate.

Exception Condition

url is null.


url contains a newline character.


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


The page request is the result of a callback.

An absolute URL (for example, or a relative URL (for example, Default.aspx) can be specified for the target location but some browsers may reject a relative URL.

When you use this method in a page handler to terminate a request for one page and start a new request for another page, set endResponse to false and then call the CompleteRequest method. If you specify true for the endResponse parameter, this method calls the End method for the original request, which throws a ThreadAbortException exception when it completes. This exception has a detrimental effect on Web application performance, which is why passing false for the endResponse parameter is recommended. For more information, see the End method.


For mobile pages, 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 create a new session and potentially lose 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.

ASP.NET performs the redirection by returning a 302 HTTP status code. An alternative way to transfer control to another page is the M:System.Web.HttpServerUtility.Transfer method. The M:System.Web.HttpServerUtility.Transfer method is typically more efficient because it does not cause a round trip to the client. For more information, see How to: Redirect Users to Another Page.

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.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<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);
            // If the browser is not connected
            // stop all response processing.

<html xmlns="" >
    <title>ASP.NET Example</title>
    <form id="form1" runat="server">

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft