IWebProxy.Credentials 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
要提交给代理服务器进行身份验证的凭据。
public:
property System::Net::ICredentials ^ Credentials { System::Net::ICredentials ^ get(); void set(System::Net::ICredentials ^ value); };
public System.Net.ICredentials Credentials { get; set; }
public System.Net.ICredentials? Credentials { get; set; }
member this.Credentials : System.Net.ICredentials with get, set
Public Property Credentials As ICredentials
属性值
ICredentials 实例,它包含对代理服务器请求进行身份验证所需的凭据。
示例
以下示例使用 Credentials 属性设置将提交到代理服务器进行身份验证的凭据。
public ref class WebProxy_Interface: public IWebProxy
{
private:
// The credentials to be used with the web proxy.
ICredentials^ iCredentials;
// Uri of the associated proxy server.
Uri^ webProxyUri;
public:
WebProxy_Interface( Uri^ proxyUri )
{
webProxyUri = proxyUri;
}
property ICredentials^ Credentials
{
// Get and Set the Credentials property.
virtual ICredentials^ get()
{
return iCredentials;
}
virtual void set( ICredentials^ value )
{
if ( iCredentials != value )
{
iCredentials = value;
}
}
}
// Return the web proxy for the specified destination (destUri).
virtual Uri^ GetProxy( Uri^ destUri )
{
// Always use the same proxy.
return webProxyUri;
}
// Return whether the web proxy should be bypassed for the specified destination (hostUri).
virtual bool IsBypassed( Uri^ hostUri )
{
// Never bypass the proxy.
return false;
}
};
public class WebProxy_Interface : IWebProxy
{
// The credentials to be used with the web proxy.
private ICredentials iCredentials;
// Uri of the associated proxy server.
private Uri webProxyUri;
public WebProxy_Interface(Uri proxyUri) {
webProxyUri = proxyUri;
}
// Get and Set the Credentials property.
public ICredentials Credentials {
get {
return iCredentials;
}
set {
if(iCredentials != value)
iCredentials = value;
}
}
// Return the web proxy for the specified destination(destUri).
public Uri? GetProxy(Uri destUri) {
// Always use the same proxy.
return webProxyUri;
}
// Return whether the web proxy should be bypassed for the specified destination(hostUri).
public bool IsBypassed(Uri hostUri) {
// Never bypass the proxy.
return false;
}
}
Public Class WebProxy_Interface
Implements IWebProxy
'The credentials to be used with the web proxy.
Private iCredentials As ICredentials
'Uri of the associated proxy server.
Private webProxyUri As Uri
Sub New(proxyUri As Uri)
webProxyUri = proxyUri
End Sub
'Get and Set the Credentials property.
Public Property Credentials() As ICredentials Implements IWebProxy.Credentials
Get
Return iCredentials
End Get
Set
If iCredentials Is value Then
iCredentials = value
End If
End Set
End Property
'Returns the web proxy for the specified destination(destUri).
Public Function GetProxy(destUri As Uri) As Uri Implements IWebProxy.GetProxy
'Always use the same proxy.
Return webProxyUri
End Function 'GetProxy
'Returns whether the web proxy should be bypassed for the specified destination(hostUri).
Public Function IsBypassed(hostUri As Uri) As Boolean Implements IWebProxy.IsBypassed
'Never bypass the proxy.
Return False
End Function 'IsBypassed
End Class
注解
属性 Credentials 是一个 ICredentials 实例,其中包含要发送到代理服务器的授权凭据,以响应 HTTP 407 (代理授权) 状态代码。