本文整理汇总了C#中NetworkCredential.GetCredential方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkCredential.GetCredential方法的具体用法?C# NetworkCredential.GetCredential怎么用?C# NetworkCredential.GetCredential使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkCredential
的用法示例。
在下文中一共展示了NetworkCredential.GetCredential方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public void ProcessRequest(HttpContext context)
{
if (context.Request.Form["javascript-enabled"] != "true")
context.Response.Redirect(HttpStatusCode.Found, "http://spammerbegone.com");
else {
using (MailMessage message = new MailMessage())
using (SmtpClient smtp = new SmtpClient())
{
string smtpHost = WebConfigurationManager.AppSettings["Smtp:Host"];
int smtpPort = Convert.ToInt32(WebConfigurationManager.AppSettings["Smtp:Port"]);
string smtpUsername = WebConfigurationManager.AppSettings["Smtp:Username"];
string smtpPassword = WebConfigurationManager.AppSettings["Smtp:Password"];
var creds = new NetworkCredential(smtpUsername, smtpPassword);
var auth = creds.GetCredential(smtpHost, smtpPort, "Basic");
smtp.Host = smtpHost;
smtp.Port = smtpPort;
smtp.Credentials = auth;
string contactName = context.Request.Form["contact-name"];
string contactEmail = context.Request.Form["contact-email"];
message.To.Add(new MailAddress(WebConfigurationManager.AppSettings["InfoEmail"], "Managed Fusion"));
message.To.Add(new MailAddress(contactEmail, contactName));
message.From = new MailAddress(WebConfigurationManager.AppSettings["NoReplyEmail"], "Managed Fusion No Reply");
message.ReplyTo = new MailAddress(contactEmail, contactName);
message.Subject = "Web Site Information Request";
message.IsBodyHtml = false;
message.Body = "sent-at:" + Environment.NewLine + DateTime.Now.ToString("F") + Environment.NewLine + Environment.NewLine;
message.Body += "sent-from:" + Environment.NewLine + "managedfusion.com" + Environment.NewLine + Environment.NewLine;
foreach (string id in context.Request.Form.AllKeys)
message.Body += id + ":" + Environment.NewLine + context.Request.Form[id] + Environment.NewLine + Environment.NewLine;
smtp.Send(message);
}
// redirect to form
context.Response.Redirect(HttpStatusCode.SeeOther, "/thank-you.aspx");
}
}
示例2: ProcessRequest
public void ProcessRequest(HttpContext context)
{
using (MailMessage message = new MailMessage())
using (SmtpClient smtp = new SmtpClient())
{
string smtpHost = WebConfigurationManager.AppSettings["Smtp:Host"];
int smtpPort = Convert.ToInt32(WebConfigurationManager.AppSettings["Smtp:Port"]);
string smtpUsername = WebConfigurationManager.AppSettings["Smtp:Username"];
string smtpPassword = WebConfigurationManager.AppSettings["Smtp:Password"];
var creds = new NetworkCredential(smtpUsername, smtpPassword);
var auth = creds.GetCredential(smtpHost, smtpPort, "Basic");
smtp.Host = smtpHost;
smtp.Port = smtpPort;
smtp.Credentials = auth;
string contactName = context.Request.Form["contact-name"];
string contactEmail = context.Request.Form["contact-email"];
message.To.Add(new MailAddress(WebConfigurationManager.AppSettings["InfoEmail"], "Berardi's Detailing"));
message.To.Add(new MailAddress(contactEmail, contactName));
message.From = new MailAddress(WebConfigurationManager.AppSettings["NoReplyEmail"], "Berardi's Detailing No Reply");
message.ReplyTo = new MailAddress(contactEmail, contactName);
message.Subject = "Web Site Information Request";
message.IsBodyHtml = false;
message.Body = "sent-at:" + Environment.NewLine + DateTime.Now.ToString("F") + Environment.NewLine + Environment.NewLine;
message.Body += "sent-from:" + Environment.NewLine + "berardisdetailing.com" + Environment.NewLine + Environment.NewLine;
foreach (string id in context.Request.Form.AllKeys)
message.Body += id + ":" + Environment.NewLine + context.Request.Form[id] + Environment.NewLine + Environment.NewLine;
smtp.Send(message);
}
// redirect to form
context.Response.Redirect("/thank-you.html");
}
示例3: GetCredential_HostPortAuthenticationType_Success
public static void GetCredential_HostPortAuthenticationType_Success()
{
NetworkCredential nc = new NetworkCredential();
Assert.Equal(nc, nc.GetCredential("host", 500, "authenticationType"));
}
示例4: GetCredential_UriAuthenticationType_Success
public static void GetCredential_UriAuthenticationType_Success()
{
NetworkCredential nc = new NetworkCredential();
Assert.Equal(nc, nc.GetCredential(new Uri("http://microsoft.com"), "authenticationType"));
}
示例5: Submit
public HttpWebResponse Submit (Uri uri, FSpot.ProgressItem progress_item)
{
this.Progress = progress_item;
Request = (HttpWebRequest) WebRequest.Create (uri);
CookieCollection cookie_collection = Cookies.GetCookies (uri);
if (uri.UserInfo != null && uri.UserInfo != String.Empty) {
NetworkCredential cred = new NetworkCredential ();
cred.GetCredential (uri, "basic");
CredentialCache credcache = new CredentialCache();
credcache.Add(uri, "basic", cred);
Request.PreAuthenticate = true;
Request.Credentials = credcache;
}
Request.ServicePoint.Expect100Continue = expect_continue;
Request.CookieContainer = new CookieContainer ();
foreach (Cookie c in cookie_collection) {
if (SuppressCookiePath)
Request.CookieContainer.Add (new Cookie (c.Name, c.Value));
else
Request.CookieContainer.Add (c);
}
Request.Method = "POST";
Request.Headers["Accept-Charset"] = "utf-8;";
//Request.UserAgent = "F-Spot Gallery Remote Client";
Request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040626 Firefox/0.9.1";
Request.Proxy = WebProxy.GetDefaultProxy ();
if (multipart) {
GenerateBoundary ();
Request.ContentType = "multipart/form-data; boundary=" + boundary;
Request.Timeout = Request.Timeout * 3;
long length = 0;
for (int i = 0; i < Items.Count; i++) {
FormItem item = (FormItem)Items[i];
length += MultipartLength (item);
}
length += end_boundary.Length + 2;
//Request.Headers["My-Content-Length"] = length.ToString ();
if (Buffer == false) {
Request.ContentLength = length;
Request.AllowWriteStreamBuffering = false;
}
} else {
Request.ContentType = "application/x-www-form-urlencoded";
}
stream_writer = new StreamWriter (Request.GetRequestStream ());
first_item = true;
for (int i = 0; i < Items.Count; i++) {
FormItem item = (FormItem)Items[i];
Write (item);
}
if (multipart)
stream_writer.Write (end_boundary + "\r\n");
stream_writer.Flush ();
stream_writer.Close ();
HttpWebResponse response;
try {
response = (HttpWebResponse) Request.GetResponse ();
//Console.WriteLine ("found {0} cookies", response.Cookies.Count);
foreach (Cookie c in response.Cookies) {
Cookies.Add (c);
}
} catch (WebException e) {
if (e.Status == WebExceptionStatus.ProtocolError
&& ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.ExpectationFailed && expect_continue) {
e.Response.Close ();
expect_continue = false;
return Submit (uri, progress_item);
}
throw new WebException (Mono.Unix.Catalog.GetString ("Unhandled exception"), e);
}
return response;
}