NetworkCredential 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为基于密码的身份验证方案(如基本、摘要式、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
- 实现
示例
下面的代码示例将 NetworkCredential 对象与一组统一资源标识符相关联, (中) URI CredentialCache。 然后, CredentialCache 它将 传递给 对象 HttpClient ,该对象使用它对 Internet 服务器的请求进行身份验证。
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) |