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客户端请求进行身份验证后,如果 PreAuthenticate 提供了 和 true 凭据,则授权标头随每个请求一起发送到与特定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 Basic

客户端:具有授权标头的 GET

服务器:200 正常

客户端:GET someUrl

服务器:401 WWW-Authenticate Basic

客户端:具有授权标头的 GET

服务器:200 正常

PreAuthenticatetrue

客户端:GET someUrl

服务器:401 WWW-Authenticate Basic

客户端:具有授权标头的 GET

服务器:200 正常

客户端:GET someUrl 和 Authorization 标头

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

适用于