当前位置: 首页>>代码示例>>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;未经允许,请勿转载。