本文整理匯總了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"));
}