共用方式為


NetworkCredential 類別

定義

提供密碼驗證配置的認證,例如基本、摘要式、NTLM 和 Kerberos 驗證。

public ref class NetworkCredential : System::Net::ICredentials, System::Net::ICredentialsByHost
public ref class NetworkCredential : System::Net::ICredentials
public class NetworkCredential : System.Net.ICredentials, System.Net.ICredentialsByHost
public class NetworkCredential : System.Net.ICredentials
type NetworkCredential = class
    interface ICredentials
    interface ICredentialsByHost
type NetworkCredential = class
    interface ICredentials
Public Class NetworkCredential
Implements ICredentials, ICredentialsByHost
Public Class NetworkCredential
Implements ICredentials
繼承
NetworkCredential
實作

範例

下列程式代碼範例會將 物件與 中的CredentialCache一組統一NetworkCredential資源標識符關聯 (URI) 。 然後,它會將 傳遞 CredentialCacheHttpClient 物件,以用它來驗證對因特網伺服器的要求。

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

CredentialCache^ myCache = gcnew CredentialCache;

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

// HttpClient lifecycle management best practices:
// https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
HttpClientHandler^ handler = gcnew HttpClientHandler();
handler->Credentials = myCache;
HttpClient^ client = gcnew HttpClient(handler);
NetworkCredential myCred = new NetworkCredential(
    SecurelyStoredUserName,SecurelyStoredPassword,SecurelyStoredDomain);

CredentialCache myCache = new CredentialCache();

myCache.Add(new Uri("http://www.contoso.com"), "Basic", myCred);
myCache.Add(new Uri("http://app.contoso.com"), "Basic", myCred);

// HttpClient lifecycle management best practices:
// https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
HttpClient client = new HttpClient(new HttpClientHandler
{
    Credentials = myCache
});
Dim myCred As New NetworkCredential(SecurelyStoredUserName, SecurelyStoredPassword, SecurelyStoredDomain)

Dim myCache As New CredentialCache()

myCache.Add(New Uri("http://www.contoso.com"), "Basic", myCred)
myCache.Add(New Uri("http://app.contoso.com"), "Basic", myCred)
       
' HttpClient lifecycle management best practices:
' https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
Dim client As New HttpClient(New HttpClientHandler With
{
    .Credentials = myCache
})

備註

類別 NetworkCredential 是基類,提供密碼式驗證配置中的認證,例如基本、摘要、NTLM 和 Kerberos。 實作 ICredentials 介面的類別,例如 CredentialCache 類別,會傳回 NetworkCredential 物件。

此類別不支援公鑰型驗證方法,例如安全套接字層 (SSL) 客戶端驗證。

建構函式

NetworkCredential()

初始化 NetworkCredential 類別的新執行個體。

NetworkCredential(String, SecureString)

使用指定的使用者名稱和密碼來初始化 NetworkCredential 類別的新執行個體。

NetworkCredential(String, SecureString, String)

使用指定的使用者名稱、密碼和網域來初始化 NetworkCredential 類別的新執行個體。

NetworkCredential(String, String)

使用指定的使用者名稱和密碼來初始化 NetworkCredential 類別的新執行個體。

NetworkCredential(String, String, String)

使用指定的使用者名稱、密碼和網域來初始化 NetworkCredential 類別的新執行個體。

屬性

Domain

取得或設定驗證認證的網域或電腦名稱。

Password

取得或設定與認證相關的使用者名稱的密碼。

SecurePassword

取得或設定密碼為 SecureString 執行個體。

UserName

取得或設定與認證相關的使用者名稱。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetCredential(String, Int32, String)

傳回指定主機、連接埠和驗證類型之 NetworkCredential 類別的執行個體。

GetCredential(Uri, String)

傳回指定統一資源識別元 (URI) 和驗證類型之 NetworkCredential 類別的執行個體。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於