HttpWebRequest.AllowAutoRedirect Property
Gets or sets a value that indicates whether the request should follow redirection responses.
[Visual Basic] Public Property AllowAutoRedirect As Boolean [C#] public bool AllowAutoRedirect {get; set;} [C++] public: __property bool get_AllowAutoRedirect(); public: __property void set_AllowAutoRedirect(bool); [JScript] 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.
Remarks
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.
Example
[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("http://www.contoso.com"), HttpWebRequest) myHttpWebRequest.MaximumAutomaticRedirections = 1 myHttpWebRequest.AllowAutoRedirect = True Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse) [C#] // Create a new HttpWebRequest Object to the mentioned URL. HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com"); myHttpWebRequest.MaximumAutomaticRedirections=1; myHttpWebRequest.AllowAutoRedirect=true; HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse(); [C++] // Create a new HttpWebRequest Object to the mentioned URL. HttpWebRequest* myHttpWebRequest = dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"http://www.contoso.com")); myHttpWebRequest->MaximumAutomaticRedirections=1; myHttpWebRequest->AllowAutoRedirect=true; HttpWebResponse* myHttpWebResponse = dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
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