WebProxy.UseDefaultCredentials 属性

定义

获取或设置 Boolean 值,该值控制 DefaultCredentials 是否随请求一起发送。Gets or sets a Boolean value that controls whether the DefaultCredentials are sent with requests.

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

属性值

Boolean

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

例外

Credentials 属性包含默认凭据以外的凭据时,尝试设置此属性。You attempted to set this property when the Credentials property contains credentials other than the default credentials.

注解

true如果此对象发出的请求 WebProxy 应在服务器请求时使用当前登录用户的凭据进行身份验证,请将此属性设置为。Set this property to true when requests made by this WebProxy 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.

下表显示了 UseDefaultCredentials 基于属性的值设置该值的效果 CredentialsThe following table shows the effect of setting the UseDefaultCredentials value, based on the value of the Credentials property.

CredentialsCredentials value UseDefaultCredentialsUseDefaultCredentials value 效果Effect
DefaultCredentials true 无效。No effect.
DefaultCredentials false Credentials 设置为 nullCredentials is set to null.
null true Credentials 设置为 DefaultCredentialsCredentials is set to DefaultCredentials.
或以外的任何值 DefaultCredentialsnullAny value other than DefaultCredentials or null truefalsetrue or false 设置会 UseDefaultCredentials 引发异常。Setting UseDefaultCredentials throws an exception.

如果 UseDefaultCredentialsfalse ,则可以将 Credentials 属性更改为任何凭据。If UseDefaultCredentials is false, you can change the Credentials property to any credentials. 如果 UseDefaultCredentialstrue ,则将 Credentials 属性从 DefaultCredentials (更改属性设置为) 时所设置的值 UseDefaultCredentials true 将引发异常。If UseDefaultCredentials is true, changing the Credentials property from DefaultCredentials (the value that is set when the UseDefaultCredentials property is set to true) will throw an exception.

适用于