HttpClientHandler.UseDefaultCredentials 属性


获取或设置一个值,该值控制处理程序是否随请求一起发送默认凭据。Gets or sets a value that controls whether default credentials are sent with requests by the handler.

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



如果使用默认凭据,则为 true;否则为 falsetrue if the default credentials are used; otherwise false. 默认值为 falseThe default value is false.



当由对象发出的请求应在服务器请求时,将此属性设置为,并 true HttpClientHandler 使用当前登录用户的凭据进行身份验证。Set this property to true when requests made by the HttpClientHandler object should, if requested by the server, be authenticated using the credentials of the currently logged on user. 对于客户端应用程序,这在大多数情况下都是所需的行为。For client applications, this is the desired behavior in most scenarios. 对于中间层应用程序(如 ASP.NET 应用程序),通常应将 Credentials 属性设置为代表其发出请求的客户端的凭据。For middle-tier applications, such as ASP.NET applications, instead of using this property, you would typically set the Credentials property to the credentials of the client on whose behalf the request is made.

此属性不会影响代理凭据。This property doesn't affect proxy credentials. 使用默认 (系统) 代理时,请使用属性显式设置凭据 DefaultProxyCredentialsWhen the default (system) proxy is being used, set credentials explicitly by using the DefaultProxyCredentials property. 当代理由属性设置时 Proxy ,通过其属性设置代理的凭据 CredentialsWhen the proxy is set by the Proxy property, set credentials for the proxy via its Credentials property.