CredentialCache 类

定义

为多个凭据提供存储空间。Provides storage for multiple credentials.

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

示例

下面的代码示例使用多CredentialCache个安全凭据初始化, 并将WebRequest这些凭据用于。The following code example initializes a CredentialCache with multiple security credentials and uses those credentials with a WebRequest.

CredentialCache^ myCache = gcnew CredentialCache;

myCache->Add( gcnew Uri( "http://www.contoso.com/" ), "Basic", gcnew NetworkCredential( UserName,SecurelyStoredPassword ) );
myCache->Add( gcnew Uri( "http://www.contoso.com/" ), "Digest", gcnew NetworkCredential( UserName,SecurelyStoredPassword,Domain ) );

wReq->Credentials = myCache;
CredentialCache myCache = new CredentialCache();

myCache.Add(new Uri("http://www.contoso.com/"),"Basic",new NetworkCredential(UserName,SecurelyStoredPassword));
myCache.Add(new Uri("http://www.contoso.com/"),"Digest", new NetworkCredential(UserName,SecurelyStoredPassword,Domain));

wReq.Credentials = myCache;
Dim myCache As New CredentialCache()

myCache.Add(New Uri("http://www.contoso.com/"), "Basic", New NetworkCredential(UserName, SecurelyStoredPassword))
myCache.Add(New Uri("http://www.contoso.com/"), "Digest", New NetworkCredential(UserName, SecurelyStoredPassword, Domain))

wReq.Credentials = myCache

注解

CredentialCache类存储多个 Internet 资源的凭据。The CredentialCache class stores credentials for multiple Internet resources. 需要访问多个资源的应用程序可以将这些资源的凭据存储在CredentialCache一个实例中, 然后在需要时向 Internet 资源提供适当的凭据集。Applications that need to access multiple resources can store the credentials for those resources in a CredentialCache instance that then provides the proper set of credentials to the Internet resource when required. GetCredential调用方法时, 它会将提供的统一资源标识符 (URI) 和身份验证类型与缓存中存储的身份验证类型进行比较, 并返回第一个匹配的凭据集。When the GetCredential method is called, it compares the Uniform Resource Identifier (URI) and authentication type provided with those stored in the cache and returns the first set of credentials that match.

DefaultCredentials属性包含当前安全上下文的系统凭据。The DefaultCredentials property contains the system credentials of the current security context. 对于客户端应用程序, 它们代表当前登录的用户的用户名、密码和域。For client applications, these represent the user name, password, and domain of the user who is currently logged in. 对于 ASP.NET 应用程序, 默认凭据是已登录用户或正在模拟的用户的用户凭据。For ASP.NET applications, the default credentials are the user credentials of the logged-in user or the user being impersonated.

构造函数

CredentialCache()

创建 CredentialCache 类的新实例。Creates a new instance of the CredentialCache class.

属性

DefaultCredentials

获取应用程序的系统凭据。Gets the system credentials of the application.

DefaultNetworkCredentials

获取当前安全上下文的网络凭据。Gets the network credentials of the current security context.

方法

Add(String, Int32, String, NetworkCredential)

向凭据缓存添加要与 SMTP 一起使用的 NetworkCredential 实例,并将其与主机、端口和身份验证协议关联。Adds a NetworkCredential instance for use with SMTP to the credential cache and associates it with a host computer, port, and authentication protocol. 使用此方法添加的凭据仅对 SMTP 有效。Credentials added using this method are valid for SMTP only. 此方法对 HTTP 或 FTP 请求无效。This method does not work for HTTP or FTP requests.

Add(Uri, String, NetworkCredential)

向凭据缓存添加一个要与 SMTP 以外的协议一起使用的 NetworkCredential 实例,并将其与统一资源标识符 (URI) 前缀和身份验证协议关联。Adds a NetworkCredential instance to the credential cache for use with protocols other than SMTP and associates it with a Uniform Resource Identifier (URI) prefix and authentication protocol.

Equals(Object)

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

(继承自 Object)
GetCredential(String, Int32, String)

返回与指定的主机、端口和身份验证协议关联的 NetworkCredential 实例。Returns the NetworkCredential instance associated with the specified host, port, and authentication protocol.

GetCredential(Uri, String)

返回与指定的统一资源标识符 (URI) 和身份验证类型相关联的 NetworkCredential 实例。Returns the NetworkCredential instance associated with the specified Uniform Resource Identifier (URI) and authentication type.

GetEnumerator()

返回可循环访问 CredentialCache 实例的枚举器。Returns an enumerator that can iterate through the CredentialCache instance.

GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
Remove(String, Int32, String)

如果 NetworkCredential 实例与指定的主机、端口和身份验证协议相关联,则将其从缓存中删除。Deletes a NetworkCredential instance from the cache if it is associated with the specified host, port, and authentication protocol.

Remove(Uri, String)

如果 NetworkCredential 实例与指定的统一资源标识符 (URI) 前缀和身份验证协议相关联,则将其从缓存中删除。Deletes a NetworkCredential instance from the cache if it is associated with the specified Uniform Resource Identifier (URI) prefix and authentication protocol.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅