当前位置: 首页>>代码示例>>C#>>正文


C# CredentialCache.GetCredential方法代码示例

本文整理汇总了C#中System.Net.CredentialCache.GetCredential方法的典型用法代码示例。如果您正苦于以下问题:C# CredentialCache.GetCredential方法的具体用法?C# CredentialCache.GetCredential怎么用?C# CredentialCache.GetCredential使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.CredentialCache的用法示例。


在下文中一共展示了CredentialCache.GetCredential方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendReport

		private void SendReport()
		{
			try
			{
				var fileName = Path.GetTempFileName();
				File.WriteAllText(fileName, report, Encoding.Unicode);

				CredentialCache credentialCache = new CredentialCache();
				credentialCache.Add(uploadUri, @"Basic", new NetworkCredential(@"uprep", @"qeiusroi123woi3zf"));

				var webClient = new WebClient();
				webClient.Credentials = credentialCache.GetCredential(uploadUri, @"Basic");
				webClient.QueryString.Add("app", "SRV");
				webClient.QueryString.Add("ver", version.ToString());
				webClient.UploadFile(uploadUri, fileName);
			}
			catch
			{
			}
		}
开发者ID:hungdluit,项目名称:sipserver,代码行数:20,代码来源:CrashHandler.cs

示例2: SendMailNotification

        private static bool SendMailNotification(NPC FoundNPC)
        {
            // Construct Message
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(user.getUser());
            msg.To.Add(strRecipientAddress);
            msg.Subject = FoundNPC.getName() + " FOUND!";
            msg.Body = FoundNPC.getName() + " (" + FoundNPC.getID().ToString("D") + ") has been cached!";
            msg.IsBodyHtml = false;
            msg.Priority = MailPriority.Normal;

            // Send the Message
            SmtpClient client = new SmtpClient();
            client.Host = server.getHostName();
            client.Port = server.getPort();
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = server.UseSSL();
            client.UseDefaultCredentials = false;
            //client.Timeout = 10000;

            CredentialCache cache = new CredentialCache();
            cache.Add(new Uri("http://" + server.getHostName()), "Basic", new NetworkCredential(user.getUser(), user.getPassword()));
            client.Credentials = cache.GetCredential(new Uri("http://" + server.getHostName()), "Basic");

            ConsoleLogMessage("Sending mail alert...", ConsoleMessage.INFO);
            client.Send(msg);

            return true;
        }
开发者ID:nbuuck,项目名称:eNPCScan,代码行数:29,代码来源:Program.cs

示例3: All

        public void All ()
        {
		CredentialCache c = new CredentialCache ();
		
		NetworkCredential cred1 = new NetworkCredential ("user1", "pwd1");
		NetworkCredential cred2 = new NetworkCredential ("user2", "pwd2");
		NetworkCredential cred3 = new NetworkCredential ("user3", "pwd3");
		NetworkCredential cred4 = new NetworkCredential ("user4", "pwd4");
		NetworkCredential cred5 = new NetworkCredential ("user5", "pwd5");
		
		c.Add (new Uri ("http://www.ximian.com"), "Basic", cred1);
		c.Add (new Uri ("http://www.ximian.com"), "Kerberos", cred2);
		
		c.Add (new Uri ("http://www.contoso.com/portal/news/index.aspx"), "Basic", cred1);
		c.Add (new Uri ("http://www.contoso.com/portal/news/index.aspx?item=1"), "Basic", cred2);
		c.Add (new Uri ("http://www.contoso.com/portal/news/index.aspx?item=12"), "Basic", cred3);
		c.Add (new Uri ("http://www.contoso.com/portal/"), "Basic", cred4);
		c.Add (new Uri ("http://www.contoso.com"), "Basic", cred5);
		
		NetworkCredential result = null;
	
		try {
			c.Add (new Uri("http://www.ximian.com"), "Basic", cred1);
			Assertion.Fail ("#1: should have failed");
		} catch (ArgumentException) { }

		c.Add (new Uri("http://www.contoso.com/"), "**Unknown**", cred1);
		result = c.GetCredential (new Uri("http://www.contoso.com/"), "**Unknown**");
		Assertion.AssertEquals ("#3", result, cred1);
		c.Remove (new Uri("http://www.contoso.com/"), "**Unknown**");
		result = c.GetCredential (new Uri("http://www.contoso.com/"), "**Unknown**");
		Assertion.Assert ("#4", result == null);

		c.Add (new Uri("http://www.contoso.com/"), "**Unknown**", cred1);
		result = c.GetCredential (new Uri("http://www.contoso.com"), "**Unknown**");
		Assertion.AssertEquals ("#5", result, cred1);
		c.Remove (new Uri("http://www.contoso.com"), "**Unknown**");
		result = c.GetCredential (new Uri("http://www.contoso.com"), "**Unknown**");
		Assertion.Assert ("#6", result == null);

		c.Add (new Uri("http://www.contoso.com/portal/"), "**Unknown**", cred1);
		result = c.GetCredential (new Uri("http://www.contoso.com/portal/foo/bar.html"), "**Unknown**");
		Assertion.AssertEquals ("#7", result, cred1);
		c.Remove (new Uri("http://www.contoso.com"), "**Unknown**");
		result = c.GetCredential (new Uri("http://www.contoso.com"), "**Unknown**");
		Assertion.Assert ("#8", result == null);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/news/index.aspx"), "Basic");
		Assertion.AssertEquals ("#9", result, cred3);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/news/index"), "Basic");
		Assertion.AssertEquals ("#10", result, cred3);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/news/"), "Basic");
		Assertion.AssertEquals ("#11", result, cred3);
		
		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/news"), "Basic");
		Assertion.AssertEquals ("#12", result, cred4);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/ne"), "Basic");
		Assertion.AssertEquals ("#13", result, cred4);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/"), "Basic");
		Assertion.AssertEquals ("#14", result, cred4);				

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal"), "Basic");
		Assertion.AssertEquals ("#15", result, cred5);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/"), "Basic");
		Assertion.AssertEquals ("#16", result, cred5);

		result = c.GetCredential (new Uri("http://www.contoso.com"), "Basic");
		Assertion.AssertEquals ("#17", result, cred5);		

		/*		
		IEnumerator e = c.GetEnumerator ();
		while (e.MoveNext ()) {
			Console.WriteLine (e.Current.GetType () + " : " + e.Current.ToString ());
		}
		*/
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:81,代码来源:CredentialCacheTest.cs

示例4: btnRestCred_Click

        private void btnRestCred_Click(object sender, RoutedEventArgs e)
        {
            string BaseUrl = "http://crm.denallix.com/Denallix/xrmservices/2011/OrganizationData.svc/AccountSet";
            //string Resource = "AccountSet?";
            var client = new RestClient();
            client.BaseUrl = BaseUrl;
            
            CredentialCache credCache = new CredentialCache();

            credCache.GetCredential(new Uri(RemoveTrailingSlash(BaseUrl)), "Negotiate"); 
 //           credCache.GetCredential(new Uri(""), "Negotiate"); 


            //credCache.GetCredential(new Uri(BaseUrl), "NTLM");

            SourceCode.Workflow.Common.Authentication.ADCredentials ad = new SourceCode.Workflow.Common.Authentication.ADCredentials();
            CredentialCache k2Cache = ad.GetCredentials(RemoveTrailingSlash(BaseUrl));

            var request = new RestRequest();
            request.Credentials = credCache;
            //request.Credentials = new NetworkCredential("holly", "K2pass!", "DENALLIX");
//            request.Credentials = request.Credentials.GetCredential(new Uri(RemoveTrailingSlash(BaseUrl)), "NTLM");
            request.Method = RestSharp.Method.GET;
            request.RequestFormat = RestSharp.DataFormat.Xml;
            //request.Resource = Resource;



            var response = client.Execute(request);
        }
开发者ID:jonnoking,项目名称:K2-Dynamics-CRM-Extensions,代码行数:30,代码来源:MainWindow.xaml.cs

示例5: SendMessage

        //Array hosts;
        /* Construct and send mail. */
        private void SendMessage()
        {
            //try
            //{
            /* Create Mail Message */
            MailMessage oMessage = new MailMessage();
            oMessage.From = new MailAddress(from);
            oMessage.To.Add(to);
            oMessage.Subject = subject;
            oMessage.Body = ebody;

            /*Set up SMTPClient */
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Host = host;
            smtpClient.Port = port;
            CredentialCache CredCache;
            NetworkCredential creds;
            string Domain;

            switch (Auth)
            {
                case 1: /* Setup Basic Auth over TLS */
                    tblkStatus.Text += "Authentication: Basic over TLS\n";
                    if (tbUserName.Text.Contains("\\") == true)
                    {
                        char[] delim = { '\\' };
                        string[] text = tbUserName.Text.Split(delim);
                        Domain = text[0];
                        UserName = text[1];
                    }
                    else if (tbUserName.Text.Contains("@") == true)
                    {
                        char[] delim = { '@' };
                        string[] text = tbUserName.Text.Split(delim);
                        Domain = text[0];
                        UserName = text[1];
                    }
                    else
                    {
                        UserName = tbUserName.Text;
                    }
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.EnableSsl = true;
                    CredCache = new CredentialCache();
                    creds = new NetworkCredential(UserName, Password, Domain);
                    CredCache.Add(new Uri("smtp://" + host + ":" + port + "/"), "BASIC", creds);
                    smtpClient.Credentials = CredCache.GetCredential(new Uri("smtp://" + host + ":" + port + "/"), "BASIC");
                    tblkStatus.Text += "Credential Cache Generated for: " + host + ":" + port + "\n";
                    string thumb = SSLThumbPrint;
                    X509Store certstore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                    certstore.Open(OpenFlags.ReadOnly);
                    var certs = certstore.Certificates;
                    if (rbSSLStore.IsChecked == true)
                    {
                        certstore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                        certstore.Open(OpenFlags.ReadOnly);
                        certs = certstore.Certificates.Find(X509FindType.FindByThumbprint, thumb, false);
                    }
                    if (rbSSLFile.IsChecked == true)
                    {
                        certstore = new X509Store();
                        string file = SSLThumbPrint;
                        certstore.Add(new X509Certificate2(file));
                        certs = certstore.Certificates;
                    }
                    if (certs.Count != 1)
                    {
                        tblkStatus.Text += string.Format("Cert Error: {0} Certs found, we only need 1", certs.Count);
                        throw new ApplicationException(string.Format("{0} certs found, we only need 1", certs.Count));

                    }
                    var name = certs[0].SubjectName.ToString();
                    X509Certificate cert = certs[0];
                    System.Windows.Forms.MessageBox.Show(name);
                    smtpClient.ClientCertificates.Add(cert);
                    break;
                case 2: /* Setup Windows Integrated Authentication */
                    tblkStatus.Text += "Authentication: NTLM\n";
                    if (tbUserName.Text.Contains("\\") == true)
                    {
                        char[] delim = { '\\' };
                        string[] text = tbUserName.Text.Split(delim);
                        Domain = text[0];
                        UserName = text[1]; ;
                    }
                    else if (tbUserName.Text.Contains("@") == true)
                    {
                        char[] delim = { '@' };
                        string[] text = tbUserName.Text.Split(delim);
                        Domain = text[0];
                        UserName = text[1];
                    }
                    else
                    {
                        UserName = tbUserName.Text;
                    }
                    smtpClient.UseDefaultCredentials = false;
                    CredCache = new CredentialCache();
//.........这里部分代码省略.........
开发者ID:kusuriya,项目名称:DeliveryBoy,代码行数:101,代码来源:MainWindow.xaml.cs

示例6: CheckOA3Key

        private bool CheckOA3Key(IHierarchicalBOM bom, IProduct p, string fkiPath, CredentialCache FKICredentialCache, string editor, UnitOfWork uow)
        {
            bool bWIN8 = false;
            IList<IBOMNode> P1BomNodeList = bom.GetFirstLevelNodesByNodeType("P1");
            //foreach (IBOMNode bomNode in P1BomNodeList)
            //{
            //    if (bomNode.Part.Descr.StartsWith("ECOA"))
            //    {
            //        bWIN8 = true;
            //        break;
            //    }
            //}
            CommonImpl2 cm2 = new CommonImpl2();
            bWIN8 = cm2.CheckIsWIN8(bom);


            if (!bWIN8) return true;

            if (fkiPath == "") return true; //Switch off checking by FKIServer.
            string thisURI = "";
            if (fkiPath.EndsWith("/"))
            {
                thisURI = fkiPath + "UnitStatus";
            }
            else
            {
                thisURI = fkiPath + "/UnitStatus";
            }

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(thisURI);
            req.AllowAutoRedirect = true;
            req.CookieContainer = new CookieContainer();
            req.ContentType = "application/plain; charset=utf-8";
            req.Accept = "*/*";
            req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
            req.KeepAlive = true;
            req.Method = "POST";
            req.Credentials = FKICredentialCache.GetCredential(new Uri(fkiPath), "NTLM");

            string XMLInputData = "<?xml version='1.0' encoding='utf-8' ?>";
            XMLInputData += "<UnitStatusRequest xmlns='http://HP.ITTS.OA30/digitaldistribution/2011/08'>";
            XMLInputData += "<HPSerialNumber>";
            XMLInputData += p.CUSTSN;
            XMLInputData += "</HPSerialNumber>";
            XMLInputData += "<ProductKeyID>";
            XMLInputData += "";
            XMLInputData += "</ProductKeyID>";
            XMLInputData += "</UnitStatusRequest>";
            Encoding encoding = Encoding.Default;
            byte[] buffer = encoding.GetBytes(XMLInputData);
            req.ContentLength = buffer.Length;
            req.GetRequestStream().Write(buffer, 0, buffer.Length);

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            XmlTextReader xmlr = new XmlTextReader(res.GetResponseStream());
            string status = "";
            string rc = "";
            bool bError = false;
            bool bFound = false;
            StringBuilder str = new StringBuilder("Formatted Response:\n");

            while (xmlr.Read())
            {
                switch (xmlr.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xmlr.IsEmptyElement)
                            str.AppendFormat("<{0}/>", xmlr.Name);
                        else
                            str.AppendFormat("<{0}>", xmlr.Name);
                        break;
                    case XmlNodeType.Text:
                        str.Append(xmlr.Value);
                        break;
                    case XmlNodeType.CDATA:
                        str.AppendFormat("<![CDATA[{0}]]>", xmlr.Value);
                        break;
                    case XmlNodeType.ProcessingInstruction:
                        str.AppendFormat("<?{0} {1}?>", xmlr.Name, xmlr.Value);
                        break;
                    case XmlNodeType.Comment:
                        str.AppendFormat("<!--{0}-->", xmlr.Value);
                        break;
                    case XmlNodeType.XmlDeclaration:
                        str.AppendFormat("<?xml version='1.0'?>");
                        break;
                    case XmlNodeType.DocumentType:
                        str.AppendFormat("<!DOCTYPE{0} [{1}]>", xmlr.Name, xmlr.Value);
                        break;
                    case XmlNodeType.EntityReference:
                        str.Append(xmlr.Name);
                        break;
                    case XmlNodeType.EndElement:
                        str.AppendFormat("</{0}>", xmlr.Name);
                        break;
                    case XmlNodeType.Whitespace:
                        str.Append("\n");
                        break;
                }

//.........这里部分代码省略.........
开发者ID:wra222,项目名称:testgit,代码行数:101,代码来源:UploadShipmentData.cs


注:本文中的System.Net.CredentialCache.GetCredential方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。