HttpWebRequest.PreAuthenticate 属性

定义

获取或设置一个值,该值指示是否随请求发送一个 Authorization 标头。Gets or sets a value that indicates whether to send an Authorization header with the request.

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

属性值

Boolean

如果在发生身份验证之后随请求一起发送 HTTP Authorization 标头,则为 true;否则为 falsetrue to send an HTTP Authorization header with requests after authentication has taken place; otherwise, false. 默认值为 falseThe default is false.

注解

成功对特定的客户端请求 Uri 进行身份验证后,如果 PreAuthenticatetrue 和提供了凭据,则会向授权标头发送每个请求,并将每个请求与 Uri Uri 上一个正斜杠匹配的所有请求一起发送。After a client request to a specific Uri is successfully authenticated, if PreAuthenticate is true and credentials are supplied, the Authorization header is sent with each request to any Uri that matches the specific Uri up to the last forward slash. 因此,如果客户端请求成功地通过身份验证为 Uri 包含以下内容的特定:So if the client request successfully authenticated to a specific Uri that contains the following:

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

然后,将每个请求发送到预身份验证的授权标头 UriThen the Authorization header for preauthentication is sent with each request to any of the following Uri instances:

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 实例:However, the Authorization header is not sent with requests to any of the following Uri instances:

http://www.contoso.com/

http://www.contoso.com/firstpath

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

如果未成功对特定的客户端请求 Uri 进行身份验证,则该请求将使用标准身份验证过程。If the client request to a specific Uri is not successfully authenticated, the request uses standard authentication procedures.

除了第一个请求之外, PreAuthenticate 属性指示是否将身份验证信息与后续请求一起发送到 Uri ,该请求与最后一个 Uri 正斜杠匹配,而不等待服务器质询。With the exception of the first request, the PreAuthenticate property indicates whether to send authentication information with subsequent requests to a Uri that matches the specific Uri up to the last forward slash without waiting to be challenged by the server.

客户端和服务器之间的以下对话框说明了此属性的效果。The following dialog between client and server illustrates the effect of this property. 此对话框假定使用的是基本身份验证。The dialog assumes that basic authentication is in use.

PreAuthenticatefalsePreAuthenticate is false:

客户端:获取 someUrlClient: GET someUrl

服务器: 401 WWW-Authenticate 基本Server: 401 WWW-Authenticate Basic

客户端:获取授权标头Client: GET with Authorization headers

服务器:200正常Server: 200 OK

客户端:获取 someUrlClient: GET someUrl

服务器: 401 WWW-Authenticate 基本Server: 401 WWW-Authenticate Basic

客户端:获取授权标头Client: GET with Authorization headers

服务器:200正常Server: 200 OK

PreAuthenticatetruePreAuthenticate is true:

客户端:获取 someUrlClient: GET someUrl

服务器: 401 WWW-Authenticate 基本Server: 401 WWW-Authenticate Basic

客户端:获取授权标头Client: GET with Authorization headers

服务器:200正常Server: 200 OK

客户端:获取具有授权标头的 someUrlClient: GET someUrl with Authorization headers

如果身份验证方案不支持预身份验证,则忽略此属性的值。If the authentication scheme does not support preauthentication, the value of this property is ignored.

适用于