本文整理汇总了C#中System.Net.ICredentials接口的典型用法代码示例。如果您正苦于以下问题:C# ICredentials接口的具体用法?C# ICredentials怎么用?C# ICredentials使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
ICredentials接口属于System.Net命名空间,在下文中一共展示了ICredentials接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CredentialInfo
class CredentialList : ICredentials
{
class CredentialInfo
{
public Uri uriObj;
public String authenticationType;
public NetworkCredential networkCredentialObj;
public CredentialInfo(Uri uriObj, String authenticationType, NetworkCredential networkCredentialObj)
{
this.uriObj = uriObj;
this.authenticationType = authenticationType;
this.networkCredentialObj = networkCredentialObj;
}
}
private ArrayList arrayListObj;
public CredentialList()
{
arrayListObj = new ArrayList();
}
public void Add (Uri uriObj, String authenticationType, NetworkCredential credential)
{
// Add a 'CredentialInfo' object into a list.
arrayListObj.Add (new CredentialInfo(uriObj, authenticationType, credential));
}
// Remove the 'CredentialInfo' object from the list that matches to the given 'Uri' and 'AuthenticationType'
public void Remove (Uri uriObj, String authenticationType)
{
for(int index=0;index < arrayListObj.Count; index++)
{
CredentialInfo credentialInfo = (CredentialInfo)arrayListObj[index];
if(uriObj.Equals(credentialInfo.uriObj)&& authenticationType.Equals(credentialInfo.authenticationType))
arrayListObj.RemoveAt(index);
}
}
public NetworkCredential GetCredential (Uri uriObj, String authenticationType)
{
for(int index=0;index < arrayListObj.Count; index++)
{
CredentialInfo credentialInfoObj = (CredentialInfo)arrayListObj[index];
if(uriObj.Equals(credentialInfoObj.uriObj) && authenticationType.Equals(credentialInfoObj.authenticationType))
return credentialInfoObj.networkCredentialObj;
}
return null;
}
};