Bewerken

Delen via


HttpClientHandler.AllowAutoRedirect Property

Definition

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

public:
 property bool AllowAutoRedirect { bool get(); void set(bool value); };
public bool AllowAutoRedirect { get; set; }
member this.AllowAutoRedirect : bool with get, set
Public Property AllowAutoRedirect As Boolean

Property Value

true if the handler should follow redirection responses; otherwise false. The default value is true.

Remarks

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

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

The Authorization header is cleared on auto-redirects and the handler automatically tries to re-authenticate to the redirected location. No other headers are cleared. In practice, this means that an application can't put custom authentication information into the Authorization header if it is possible to encounter redirection. Instead, the application must implement and register a custom authentication module.

If you are using cookies by specifically adding them to the Headers collection, these are not cleared when a redirect is followed, as the handler has no way of knowing what domain a cookie is allowed for. If you want to mimic browser behavior, use the CookieContainer class which allows you to specify the target domain for a cookie.

Note

With AllowAutoRedirect set to true, the .NET Framework will follow redirections even when being redirected to an HTTP URI from an HTTPS URI. .NET Core versions 1.0, 1.1 and 2.0 will not follow a redirection from HTTPS to HTTP even if AllowAutoRedirect is set to true.

Applies to