HttpResponse.Redirect Method (String)

Redirects a client to a new URL and specifies the new URL.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

C#
public void Redirect (
	string url
)
J#
public void Redirect (
	String url
)
public function Redirect (
	url : String
)

Parameters

url

The target location.

Exception type Condition

HttpException1

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

Calling Redirect is equivalent to calling Redirect2 with the second parameter set to true.

Redirect calls End3 which raises a ThreadAbortException4 exception upon completion.

The following example forces an unconditional redirection to another Web site.

C#
Response.Redirect("http://www.microsoft.com/gohere/look.htm");
   

J#
get_Response().Redirect("http://www.microsoft.com/gohere/look.htm");

Response.Redirect("http://www.microsoft.com/gohere/look.htm")
   

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 Requirements5.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Links Table
1http://msdn.microsoft.com/en-us/library/system.web.httpexception(v=vs.80).aspx
2http://msdn.microsoft.com/en-us/library/system.web.httpresponse.redirect(v=vs.80).aspx
3http://msdn.microsoft.com/en-us/library/system.web.httpresponse.end(v=vs.80).aspx
4http://msdn.microsoft.com/en-us/library/system.threading.threadabortexception(v=vs.80).aspx
5http://msdn.microsoft.com/en-us/library/8z6watww(v=vs.80).aspx
6http://msdn.microsoft.com/en-us/library/system.web.httpresponse(v=vs.80).aspx
7http://msdn.microsoft.com/en-us/library/system.web.httpresponse_members(v=vs.80).aspx
8http://msdn.microsoft.com/en-us/library/system.web(v=vs.80).aspx
Community Content Add
Annotations FAQ
Encoding characters

If the redirected url includes user-entered data, such as

http://www.test.com/newpage.aspx?country=USA

Then, the querystring component should be urlencoded.

Response.redirect("http://www.test.com/newpage.aspx?country=" + HttpUtility.UrlEncode(TheCountry))

This way, the correct url will be generated for countries like

http://www.test.com/newpage.aspx?country=Sri%20Lanka