HttpWebRequest.PreAuthenticate 属性

定义

获取或设置一个值,该值指示是否随请求发送一个 Authorization 标头。

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

属性值

true 在进行身份验证后发送包含请求的 HTTP 授权标头;否则为 false。 默认为 false

注解

成功对特定Uri客户端请求进行身份验证后,如果PreAuthenticatetrue提供了 ,并且提供了凭据,则授权标头将随每个请求一起发送到任何Uri与特定 Uri 匹配的 ,以及最后一个正斜杠。 因此,如果客户端请求成功对包含以下内容的特定 Uri 进行身份验证:

http://www.contoso.com/firstpath/

然后,将预身份验证的 Authorization 标头与每个请求一起发送到以下 Uri 任一实例:

http://www.contoso.com/firstpath/

http://www.contoso.com/firstpath/default

http://www.contoso.com/firstpath/default.html

http://www.contoso.com/firstpath/sample.html

但是,授权标头不会随请求一起发送到以下 Uri 任何实例:

http://www.contoso.com/

http://www.contoso.com/firstpath

http://www.contoso.com/secondpath/

http://www.contoso.com/firstpath/thirdpath/

如果对特定 Uri 的客户端请求未成功进行身份验证,则请求使用标准身份验证过程。

除了第一个请求之外, PreAuthenticate 属性指示是否将身份验证信息与后续请求一起发送到 ,该请求与特定的 Uri 直到最后一个Uri正斜杠匹配,而不会等待服务器质询。

客户端和服务器之间的以下对话框演示了此属性的效果。 该对话框假定正在使用基本身份验证。

PreAuthenticatefalse

客户端:GET someUrl

服务器:401 WWW-Authenticate 基本版

客户端:GET 和授权标头

服务器:200 正常

客户端:GET someUrl

服务器:401 WWW-Authenticate 基本版

客户端:GET 和授权标头

服务器:200 正常

PreAuthenticatetrue

客户端:GET someUrl

服务器:401 WWW-Authenticate 基本版

客户端:GET 和授权标头

服务器:200 正常

客户端:GET someUrl 和 Authorization 标头

如果身份验证方案不支持预身份验证,则忽略此属性的值。

适用于