Export (0) Print
Expand All

HttpWebRequest.MaximumAutomaticRedirections Property

Gets or sets the maximum number of redirects that the request follows.

Namespace: System.Net
Assembly: System (in system.dll)

'Declaration
Public Property MaximumAutomaticRedirections As Integer
'Usage
Dim instance As HttpWebRequest
Dim value As Integer

value = instance.MaximumAutomaticRedirections

instance.MaximumAutomaticRedirections = value
/** @property */
public int get_MaximumAutomaticRedirections ()

/** @property */
public void set_MaximumAutomaticRedirections (int value)

public function get MaximumAutomaticRedirections () : int

public function set MaximumAutomaticRedirections (value : int)

Not applicable.

Property Value

The maximum number of redirection responses that the request follows. The default value is 50.

Exception typeCondition

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.

Imports System
Imports System.Net
Imports System.Text
Imports System.IO


    Public Class Test

        ' Specify the URL to receive the request.
        Public Shared Sub Main(ByVal args() As String)
        Dim request As HttpWebRequest = CType(WebRequest.Create(args(0)), HttpWebRequest)


        ' 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

        Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

        Console.WriteLine("Content length is {0}", response.ContentLength)
        Console.WriteLine("Content type is {0}", response.ContentType)

        ' Get the stream associated with the response.
        Dim receiveStream As Stream = response.GetResponseStream()

        ' Pipes the stream to a higher level stream reader with the required encoding format. 
        Dim readStream As New StreamReader(receiveStream, Encoding.UTF8)

        Console.WriteLine("Response stream received.")
        Console.WriteLine(readStream.ReadToEnd())
        response.Close()
        readStream.Close()
    End Sub 'Main
End Class 'Test
'
'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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft