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

属性值

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

注解

成功对特定 Uri 的客户端请求进行身份验证后,如果 PreAuthenticate true 并且提供了凭据,则会将授权标头与每个请求一起发送到与特定 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. 因此,如果客户端请求成功地通过身份验证到了包含以下各项的特定 UriSo if the client request successfully authenticated to a specific Uri that contains the following:

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

然后,预身份验证的授权标头随每个请求发送到以下 Uri 实例:Then 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.

falsePreAuthenticatePreAuthenticate is false:

客户端:获取 someUrlClient: GET someUrl

服务器: 401 WWW-身份验证基本Server: 401 WWW-Authenticate Basic

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

服务器:200正常Server: 200 OK

客户端:获取 someUrlClient: GET someUrl

服务器: 401 WWW-身份验证基本Server: 401 WWW-Authenticate Basic

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

服务器:200正常Server: 200 OK

truePreAuthenticatePreAuthenticate is true:

客户端:获取 someUrlClient: GET someUrl

服务器: 401 WWW-身份验证基本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.

适用于