HttpResponse::Redirect Method (String, Boolean)
Updated: May 2011
Redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.
Assembly: System.Web (in System.Web.dll)
Parameters
- url
- Type: System::String
The location of the target.
- endResponse
- Type: System::Boolean
Indicates whether execution of the current page should terminate.
| Exception | Condition |
|---|---|
| ArgumentNullException | url is nullptr. |
| 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.
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 true or call the Redirect method overload. This method calls End for the original request, which throws a ThreadAbortException exception upon completion.
When you call this method in an HTTP handler and you want to redirect to another page without terminating the request, set endResponse to false.
Note: |
|---|
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. |
ASP.NET performs the redirection by returning a 302 HTTP status code. An alternative way to transfer control to another page is the Transfer method. The 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.
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.
Note: