几个小技巧:发送邮件,获取客户IP,获取CreateUserWizardStep中的控件

1. 发送邮件

发送邮件主要使用 System.Net.Mail 下的两个类。

public static bool Send(string rec,string recName)
{
    MailMessage msg = new MailMessage();
    msg.To.Add(new MailAddress(rec));
    msg.From = new MailAddress(MailConfigure.Sender, MailConfigure.SenderName, Encoding.UTF8);

    msg.Subject = MailConfigure.Title;
    msg.SubjectEncoding = Encoding.UTF8;
    msg.Body = “Message body goes here”;
    msg.BodyEncoding = Encoding.UTF8;
    msg.IsBodyHtml = false;

    SmtpClient client = new SmtpClient();
    client.Credentials = new System.Net.NetworkCredential(MailConfigure.Sender, MailConfigure.SenderPwd);
    client.Port = 587;  //465 or 587 
    client.Host = MailConfigure.SMTPServer;

    client.EnableSsl = true;    //经过SSL加密

    object userState = msg;

    try
    {
        client.Send(msg);
        return true;
    }
    catch (SmtpException ex)
    {
        Logger.Log(ex);
    }
    return false;
}

2. 获取客户IP

string ip = System.Web.HttpContext.Current.Request.UserHostAddress;

3. 获得CreateUserWizardStep中的控件。如果在CreateUserWizardStep中放置了自己的控件,在代码中是取不到的。如果要获取可以使用如下代码:

Control_UserProfile p = CreateUserWizard1.WizardSteps[0].Controls[0].FindControl("UserProfile1" ) as Control_UserProfile;

 

原文地址:https://www.cnblogs.com/yinzixin/p/1726001.html