HttpClientHandler.AllowAutoRedirect 属性

定义

获取或设置一个值,该值指示处理程序是否应跟随重定向响应。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

属性值

Boolean

true 如果处理程序应跟随重定向响应,则为;否则为 falsetrue if the handler should follow redirection responses; otherwise false. 默认值为 trueThe default value is true.

注解

AllowAutoRedirect true 如果希望处理程序自动跟随 HTTP 重定向标头到资源的新位置,则设置为。Set AllowAutoRedirect to true if you want the handler to automatically follow HTTP redirection headers to the new location of the resource. 要遵循的重定向的最大数目由 MaxAutomaticRedirections 属性设置。The maximum number of redirections to follow is set by the MaxAutomaticRedirections property.

如果 AllowAutoRedirect 设置为,则将 false http 状态代码从300到399的所有 http 响应返回到应用程序。If AllowAutoRedirect is set to false, all HTTP responses with an HTTP status code from 300 to 399 are returned to the application.

在自动重定向时清除了 Authorization 标头,并且处理程序会自动尝试对重定向的位置重新进行身份验证。The Authorization header is cleared on auto-redirects and the handler automatically tries to re-authenticate to the redirected location. 在实践中,这意味着应用程序无法将自定义身份验证信息放入授权标头(如果可能遇到重定向)。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.

备注

AllowAutoRedirect 设置为的 true 情况下,即使从 HTTPS uri 重定向到 HTTP uri,.NET Framework 也会跟随重定向。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 版本1.0、1.1 和2.0 也不会跟随从 HTTPS 到 HTTP 的重定向 AllowAutoRedirect true.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.

适用于