This documentation is archived and is not being maintained.
HttpWebRequest::MaximumAutomaticRedirections Property
Visual Studio 2010
Gets or sets the maximum number of redirects that the request follows.
Assembly: System (in System.dll)
Property Value
Type: System::Int32The maximum number of redirection responses that the request follows. The default value is 50.
| Exception | Condition |
|---|---|
| ArgumentException | The value is set to 0 or less. |
The MaximumAutomaticRedirections property sets the maximum number of redirections for the request to follow if the AllowAutoRedirect property is true.
The following code example sets the value of this property.
#using <System.dll> using namespace System; using namespace System::Net; using namespace System::Text; using namespace System::IO; // Specify the URL to receive the request. int main() { array<String^>^args = Environment::GetCommandLineArgs(); HttpWebRequest^ request = dynamic_cast<HttpWebRequest^>(WebRequest::Create( args[ 1 ] )); // Set some reasonable limits on resources used by this request request->MaximumAutomaticRedirections = 4; request->MaximumResponseHeadersLength = 4; // Set credentials to use for this request. request->Credentials = CredentialCache::DefaultCredentials; HttpWebResponse^ response = dynamic_cast<HttpWebResponse^>(request->GetResponse()); Console::WriteLine( "Content length is {0}", response->ContentLength ); Console::WriteLine( "Content type is {0}", response->ContentType ); // Get the stream associated with the response. Stream^ receiveStream = response->GetResponseStream(); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader^ readStream = gcnew StreamReader( receiveStream,Encoding::UTF8 ); Console::WriteLine( "Response stream received." ); Console::WriteLine( readStream->ReadToEnd() ); response->Close(); readStream->Close(); } /* The output from this example will vary depending on the value passed into Main but will be similar to the following: Content length is 1542 Content type is text/html; charset=utf-8 Response stream received. <html> ... </html> */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: