本文整理汇总了C#中System.Net.CredentialCache.LookupCredential方法的典型用法代码示例。如果您正苦于以下问题:C# CredentialCache.LookupCredential方法的具体用法?C# CredentialCache.LookupCredential怎么用?C# CredentialCache.LookupCredential使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.CredentialCache
的用法示例。
在下文中一共展示了CredentialCache.LookupCredential方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestLookupCredentialWithCredentialCache
public void TestLookupCredentialWithCredentialCache()
{
var credentials = new CredentialCache();
var credPopuser1 = new NetworkCredential("popuser1", "password");
var credPopuser2 = new NetworkCredential("popuser2", "password");
var credImapuser1 = new NetworkCredential("imapuser1", "password");
var credImapuser2 = new NetworkCredential("imapuser2", "password");
credentials.Add("localhost", 110, string.Empty, credPopuser1);
credentials.Add("localhost", 110, "cram-md5", credPopuser2);
credentials.Add("localhost", 143, string.Empty, credImapuser1);
credentials.Add("localhost", 143, "digest-md5", credImapuser2);
Assert.AreEqual(credPopuser1, credentials.LookupCredential("localhost", 110, "popuser1", null));
Assert.AreEqual(credPopuser2, credentials.LookupCredential("localhost", 110, "popuser2", "CRAM-MD5"));
Assert.AreEqual(credImapuser1, credentials.LookupCredential("localhost", 143, "imapuser1", null));
Assert.AreEqual(credImapuser2, credentials.LookupCredential("localhost", 143, "imapuser2", "DIGEST-MD5"));
Assert.AreEqual(credPopuser1, credentials.LookupCredential("localhost", 110, null, null));
Assert.AreEqual(credPopuser2, credentials.LookupCredential("localhost", 110, null, "CRAM-MD5"));
Assert.IsNull(credentials.LookupCredential("localhost", 110, null, "DIGEST-MD5"));
Assert.AreEqual(credImapuser1, credentials.LookupCredential("localhost", 143, null, null));
Assert.AreEqual(credImapuser2, credentials.LookupCredential("localhost", 143, null, "DIGEST-MD5"));
Assert.IsNull(credentials.LookupCredential("localhost", 143, null, "CRAM-MD5"));
}