This documentation is archived and is not being maintained.

HttpWebRequest.AllowAutoRedirect Property

Gets or sets a value that indicates whether the request should follow redirection responses.

[Visual Basic]
Public Property AllowAutoRedirect As Boolean
public bool AllowAutoRedirect {get; set;}
public: __property bool get_AllowAutoRedirect();
public: __property void set_AllowAutoRedirect(bool);
public function get AllowAutoRedirect() : Boolean;
public function set AllowAutoRedirect(Boolean);

Property Value

true if the request should automatically follow redirection responses from the Internet resource; otherwise false. The default value is true.


Set AllowAutoRedirect to true if you want the request to automatically follow HTTP redirection headers to the new location of the resource. The maximum number of redirections to follow is set by the MaximumAutomaticRedirections property.

If AllowAutoRedirect is set to false all responses with an HTTP status code from 300 to 399 will be returned to the application.


[Visual Basic, C#, C++] The following example uses the AllowAutoRedirect property to allow the request to follow redirection responses.

[Visual Basic] 

     'This method creates a new HttpWebRequest Object to the mentioned URL.
         Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(""), HttpWebRequest)
         myHttpWebRequest.MaximumAutomaticRedirections = 1
         myHttpWebRequest.AllowAutoRedirect = True
         Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

// Create a new HttpWebRequest Object to the mentioned URL.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("");    
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();    

// Create a new HttpWebRequest Object to the mentioned URL.
HttpWebRequest* myHttpWebRequest =
HttpWebResponse* myHttpWebResponse =

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

HttpWebRequest Class | HttpWebRequest Members | System.Net Namespace