當前位置: 首頁>>代碼示例>>C#>>正文


C# CredentialCache.LookupCredential方法代碼示例

本文整理匯總了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"));
        }
開發者ID:pengyancai,項目名稱:cs-util,代碼行數:26,代碼來源:ICredentialsByHostExtensions.cs


注:本文中的System.Net.CredentialCache.LookupCredential方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。