NetworkCredential NetworkCredential NetworkCredential NetworkCredential Class

定义

为基于密码的身份验证方案(如基本、简要、NTLM 和 Kerberos 身份验证)提供凭据。Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.

public ref class NetworkCredential : System::Net::ICredentials, System::Net::ICredentialsByHost
public class NetworkCredential : System.Net.ICredentials, System.Net.ICredentialsByHost
type NetworkCredential = class
    interface ICredentials
    interface ICredentialsByHost
Public Class NetworkCredential
Implements ICredentials, ICredentialsByHost
继承
NetworkCredentialNetworkCredentialNetworkCredentialNetworkCredential
实现

示例

下面的代码示例相关联NetworkCredential对象具有一系列统一资源标识符 (Uri) 中CredentialCacheThe following code example associates a NetworkCredential object with a set of Uniform Resource Identifiers (URIs) in a CredentialCache. 然后将其传递CredentialCacheWebRequest对象,使用它来与 Internet 服务器的请求进行身份验证。It then passes the CredentialCache to a WebRequest object, which uses it to authenticate requests to an Internet server.

NetworkCredential^ myCred = gcnew NetworkCredential(
   SecurelyStoredUserName,SecurelyStoredPassword,SecurelyStoredDomain );

CredentialCache^ myCache = gcnew CredentialCache;

myCache->Add( gcnew Uri( "www.contoso.com" ), "Basic", myCred );
myCache->Add( gcnew Uri( "app.contoso.com" ), "Basic", myCred );

WebRequest^ wr = WebRequest::Create( "www.contoso.com" );
wr->Credentials = myCache;
NetworkCredential myCred = new NetworkCredential(
	SecurelyStoredUserName,SecurelyStoredPassword,SecurelyStoredDomain);
 
CredentialCache myCache = new CredentialCache();
 
myCache.Add(new Uri("www.contoso.com"), "Basic", myCred);
myCache.Add(new Uri("app.contoso.com"), "Basic", myCred);
 
WebRequest wr = WebRequest.Create("www.contoso.com");
wr.Credentials = myCache;

Dim myCred As New NetworkCredential(SecurelyStoredUserName,SecurelyStoredPassword,SecurelyStoredDomain )
       
Dim myCache As New CredentialCache()
       
myCache.Add(New Uri("www.contoso.com"), "Basic", myCred)
myCache.Add(New Uri("app.contoso.com"), "Basic", myCred)
       
Dim wr As WebRequest = WebRequest.Create("www.contoso.com")
wr.Credentials = myCache

注解

NetworkCredential类是一个基类,它提供在基于密码的身份验证方案,例如,基本、 摘要式、 NTLM 和 Kerberos 凭据。The NetworkCredential class is a base class that supplies credentials in password-based authentication schemes such as basic, digest, NTLM, and Kerberos. 类实现ICredentials接口,如CredentialCache类中,返回NetworkCredential对象。Classes that implement the ICredentials interface, such as the CredentialCache class, return NetworkCredential objects.

此类不支持公共基于密钥的身份验证方法,如安全套接字层 (SSL) 客户端身份验证。This class does not support public key-based authentication methods such as Secure Sockets Layer (SSL) client authentication.

构造函数

NetworkCredential() NetworkCredential() NetworkCredential() NetworkCredential()

初始化 NetworkCredential 类的新实例。Initializes a new instance of the NetworkCredential class.

NetworkCredential(String, SecureString) NetworkCredential(String, SecureString) NetworkCredential(String, SecureString) NetworkCredential(String, SecureString)

用指定的用户名和密码初始化 NetworkCredential 类的新实例。Initializes a new instance of the NetworkCredential class with the specified user name and password.

NetworkCredential(String, SecureString, String) NetworkCredential(String, SecureString, String) NetworkCredential(String, SecureString, String) NetworkCredential(String, SecureString, String)

用指定的用户名、密码和域初始化 NetworkCredential 类的新实例。Initializes a new instance of the NetworkCredential class with the specified user name, password, and domain.

NetworkCredential(String, String) NetworkCredential(String, String) NetworkCredential(String, String) NetworkCredential(String, String)

用指定的用户名和密码初始化 NetworkCredential 类的新实例。Initializes a new instance of the NetworkCredential class with the specified user name and password.

NetworkCredential(String, String, String) NetworkCredential(String, String, String) NetworkCredential(String, String, String) NetworkCredential(String, String, String)

用指定的用户名、密码和域初始化 NetworkCredential 类的新实例。Initializes a new instance of the NetworkCredential class with the specified user name, password, and domain.

属性

Domain Domain Domain Domain

获取或设置验证凭据的域名或计算机名。Gets or sets the domain or computer name that verifies the credentials.

Password Password Password Password

获取或设置与凭据关联的用户名的密码。Gets or sets the password for the user name associated with the credentials.

SecurePassword SecurePassword SecurePassword SecurePassword

获取或设置 SecureString 实例形式的密码。Gets or sets the password as a SecureString instance.

UserName UserName UserName UserName

获取或设置与凭据关联的用户名。Gets or sets the user name associated with the credentials.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetCredential(String, Int32, String) GetCredential(String, Int32, String) GetCredential(String, Int32, String) GetCredential(String, Int32, String)

针对指定的主机、端口和身份验证类型返回 NetworkCredential 类的实例。Returns an instance of the NetworkCredential class for the specified host, port, and authentication type.

GetCredential(Uri, String) GetCredential(Uri, String) GetCredential(Uri, String) GetCredential(Uri, String)

针对指定的统一资源标识符 (URI) 和身份验证类型返回 NetworkCredential 类的实例。Returns an instance of the NetworkCredential class for the specified Uniform Resource Identifier (URI) and authentication type.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于