SocketsHttpHandler.AllowAutoRedirect Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
The handler never follows a redirection from HTTPS to HTTP even if AllowAutoRedirect is set to true
.
Applies to
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應