SocketsHttpHandler.AllowAutoRedirect 属性

定义

获取或设置一个值,该值指示处理程序是否应跟随重定向响应。

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

属性值

true 如果处理程序应遵循重定向响应,则为 ;否则为 false。 默认值是 true

注解

true如果希望处理程序自动遵循 HTTP 重定向标头到资源的新位置,请将 设置为 AllowAutoRedirect 。 要遵循的最大重定向数由 MaxAutomaticRedirections 属性设置。

如果 AllowAutoRedirect 设置为 false,则 HTTP 状态代码为 300 到 399 的所有 HTTP 响应将返回到应用程序。

授权标头在自动重定向时被清除,处理程序会自动尝试对重定向的位置重新进行身份验证。 不会清除其他标头。 实际上,这意味着如果应用程序可能遇到重定向,则无法将自定义身份验证信息放入 Authorization 标头。 相反,应用程序必须实现并注册自定义身份验证模块。

如果通过专门将 Cookie 添加到集合来 Headers 使用 Cookie,则跟踪重定向时不会清除这些 Cookie,因为处理程序无法知道允许 Cookie 用于哪个域。 如果要模拟浏览器行为,请使用 类, CookieContainer 该类允许你为 Cookie 指定目标域。

注意

处理程序永远不会遵循从 HTTPS 到 HTTP 的重定向,即使 AllowAutoRedirect 设置为 true

适用于