/// <summary> /// 新用户申请通知 /// </summary> public static void SendMailOfHandle(Account account, string modelName) { try { MailHelper mailHelper = GetMailHelper(); MailMessageTemplate mt = new MailMessageTemplate("UserEmailConfig.xml", "新用户申请通知"); string subject = mt.Subject.Replace("${LoginName}", account.LoginName); subject = subject.Replace("${ContentModelName}", modelName); string message = mt.Body.Replace("${LoginName}", account.LoginName); HttpContext context = HttpContext.Current; string url = "http://" + context.Request.Url.Host; if (context.Request.Url.Port != 80) { url += ":" + context.Request.Url.Port.ToString(); } message = message.Replace("${HandleUrl}", String.Format("{0}", url + "/admin/Permissions/AccountEdit.aspx?id=" + account.ID)); message = We7Helper.ConvertTextToHtml(message); mailHelper.Send(GeneralConfigs.GetConfig().NotifyMail, mailHelper.AdminEmail, subject, message, "Low"); } catch (Exception ex) { We7.Framework.LogHelper.WriteLog(typeof(AccountMails), ex); throw ex; } }
/// <summary> /// 设置RssItem /// </summary> /// <param name="list"></param> /// <param name="channel"></param> private void SetRssItems(List <Article> list, RssChannel channel) { List <RssItem> l = new List <RssItem>(); foreach (Article article in list) { FormatArticleUrl(article); RssItem item = new RssItem(); item.Author = article.Author; item.Link = article.LinkUrl; item.Title = article.Title; if (!string.IsNullOrEmpty(article.Description)) { item.Description = article.Description; } else { string content = We7Helper.RemoveHtml(article.Content); content = content.Replace(" ", ""); content = We7Helper.ConvertTextToHtml(content); if (content.Length > 200) { content = content.Substring(0, 200) + "..."; } item.Description = content; } item.PubDate = article.Created.ToString("yyyy-MM-dd"); l.Add(item); } channel.Rssitem = l; }
string GetErrorsMessage() { string noExceptionFound = "系统没有提供更多错误信息。"; StringBuilder exceptionMsgs = new StringBuilder(); string logContent = ""; if (Server.GetLastError() != null) { Exception ex = Server.GetLastError().GetBaseException(); while (null != ex) // this is obsolete since we're grabbing base... { if (ex is System.IO.FileNotFoundException) { exceptionMsgs.Append("<p>您请求的资源没有找到。</p>"); } else { exceptionMsgs.AppendFormat("<p>{0}</p>", We7Helper.ConvertTextToHtml(ex.Message.Trim())); logContent += "错误源:" + ex.Source + "\r\n"; logContent += "错误信息:" + ex.Message + "\r\n"; logContent += "堆栈信息:" + "\r\n" + ex.StackTrace + "\r\n"; } ex = ex.InnerException; } } else { exceptionMsgs.Append("<p>未知错误。如反复出现,请及时与产品开发商联系。非常感谢!</p>"); } Server.ClearError(); if (exceptionMsgs.Length == 0) { exceptionMsgs.Append(noExceptionFound); } if (logContent.Length > 0) { logContent = "访问页面:" + Request.RawUrl + "\r\n" + logContent; logContent = "站点IP:" + Request.ServerVariables.Get("Local_Addr").ToString() + "\r\n" + logContent; Logger.Error(logContent); ViewLogHyperlink.Text = "查看详细错误日志"; ViewLogHyperlink.NavigateUrl = Logger.GetFileName(); ViewLogHyperlink.Target = "_blank"; } return(exceptionMsgs.ToString()); }
/// <summary> /// 用户付款成功通知 /// </summary> public static void SendMailOfSuccessPay(Account account, string productName, decimal payMoney) { try { MailHelper mailHelper = GetMailHelper(); MailMessageTemplate mt = new MailMessageTemplate("UserEmailConfig.xml", "付款成功通知"); string subject = mt.Subject.Replace("${ProductName}", "[" + productName + "]"); string message = mt.Body.Replace("${LoginName}", account.LoginName).Replace("${ProductName}", "[" + productName + "]"); message = message.Replace("${PayMoney}", string.Format("{0:C2}", payMoney)); message = We7Helper.ConvertTextToHtml(message); mailHelper.Send(account.Email, mailHelper.AdminEmail, subject, message, "Low"); } catch (Exception ex) { We7.Framework.LogHelper.WriteLog(typeof(AccountMails), ex); throw ex; } }
/// <summary> /// 账号审核通过通知 /// </summary> /// <param name="accountId"></param> /// <param name="modelName"></param> /// <param name="message"></param> public static void SendMailOfPassNotify(Account account, string modelName, string message) { try { MailHelper mailHelper = GetMailHelper(); MailMessageTemplate mt = new MailMessageTemplate("UserEmailConfig.xml", "账号审核通过通知"); string subject = mt.Subject.Replace("${ContentModelName}", modelName); if (string.IsNullOrEmpty(message)) { message = mt.Body; } message = message.Replace("${LoginName}", account.LoginName); message = message.Replace("${ContentModelName}", modelName); message = We7Helper.ConvertTextToHtml(message); mailHelper.Send(account.Email, mailHelper.AdminEmail, subject, message, "Low"); } catch (Exception ex) { We7.Framework.LogHelper.WriteLog(typeof(AccountMails), ex); throw ex; } }
/// <summary> /// 新注册用户通知本人 /// </summary> /// <param name="accountId"></param> /// <param name="password"></param> /// <param name="message"></param> public static void SendMailOfRegister(Account account, string password, string message) { try { MailHelper mailHelper = GetMailHelper(); if (String.IsNullOrEmpty(mailHelper.AdminEmail)) { throw new Exception("邮件发送失败"); } MailMessageTemplate mt = new MailMessageTemplate("UserEmailConfig.xml", "新建用户通知"); if (String.IsNullOrEmpty(mt.Body)) { mt.Body = String.Empty; } if (String.IsNullOrEmpty(mt.Subject)) { mt.Subject = String.Empty; } string subject = mt.Subject.Replace("${LoginName}", account.LoginName); if (string.IsNullOrEmpty(message)) { message = mt.Body.Replace("${LoginName}", account.LoginName); } else { message = message.Replace("${LoginName}", account.LoginName); } message = message.Replace("${Password}", password); message = We7Helper.ConvertTextToHtml(message); mailHelper.Send(account.Email, mailHelper.AdminEmail, subject, message, "Low"); } catch (Exception ex) { We7.Framework.LogHelper.WriteLog(typeof(AccountMails), ex); throw ex; } }
protected void ResetDBInfo_Click(object sender, EventArgs e) { #region 验证输入 //验证密码长度 if (AdminPasswordTextBox.Text.Length < 6) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统管理员密码长度不能少于6位');</script>"); return; } //验证数据库名为空 if (DatabaseTextBox.Text.Length == 0 && DbTypeDropDownList.SelectedValue == "SqlServer") { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('数据库名不能为空');</script>"); return; } //验证必须选择数据库类型 if (DbTypeDropDownList.SelectedIndex == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择数据库类型');</script>"); return; } #endregion #region 写Site.config文件 try { SiteConfigInfo __configinfo; //记录存储到SiteConfig.config try { __configinfo = SiteConfigs.GetConfig(); } catch { __configinfo = new SiteConfigInfo(); } __configinfo.AdministratorKey = Encrypt(AdminPasswordTextBox.Text); __configinfo.IsPasswordHashed = true; __configinfo.SiteName = WebsiteNameTextBox.Text; __configinfo.AdministratorName = AdminNameTextBox.Text; SiteConfigs.Serialiaze(__configinfo, Server.MapPath("~/config/site.config")); Session["SystemAdminName"] = AdminNameTextBox.Text; Session["SystemAdminPws"] = AdminPasswordTextBox.Text; } catch {; } #endregion string setupDbType = SelectDB = DbTypeDropDownList.SelectedValue; DatabaseInfo dbi = new DatabaseInfo(); dbi.Server = ServerTextBox.Text; dbi.Database = DatabaseTextBox.Text; dbi.User = UserTextBox.Text; dbi.Password = PasswordTextBox.Text; dbi.DBFile = DbFileNameTextBox.Text; BaseConfigInfo baseConfig = Installer.GenerateConnectionString(setupDbType, dbi); //验证链接 if (!SaveDBConfig(baseConfig)) { ResetDBInfo.Enabled = false; Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>if(confirm('无法把设置写入\"db.config\"文件, 系统将把文件内容显示出来, 您可以将内容保存为\"db.config\", 然后通过FTP软件上传到网站根目录下.. \\r\\n*注意: db.config位于网站Config目录。\\r\\n\\r\\n如果要继续运行安装, 请点击\"确定\"按钮. ')) {window.location.href='step4.aspx?isforceload=1';}else{window.location.href='step3.aspx';}</script>"); return; } //下面数据库需要手工创建 if (baseConfig.DBType == "Oracle" || baseConfig.DBType == "MySql") { CreateNewDBCheckBox.Checked = false; } if (CreateNewDBCheckBox.Checked)//创建数据库 { Exception ex = null; int ret = Installer.CreateDatabase(baseConfig, out ex); if (ret == -1) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('数据库已存在,请重新命名或去掉重新“创建新数据库”前面的勾,使用已有数据库。');</script>"); return; } else if (ret == 0) { string exceptionMsgs = We7Helper.ConvertTextToHtml(ex.Message); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('创建数据库发生错误。错误原因:" + exceptionMsgs + "');</script>"); return; } } string msg = ""; if (!Installer.CheckConnection(baseConfig, out msg)) { msg = We7Helper.ConvertTextToHtml(msg); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('连接数据库失败,请检查您填写的数据库信息。" + msg + "');</script>"); return; } else { Response.Redirect(Server.HtmlEncode(String.Format("step4.aspx?db={0}", setupDbType))); } }
protected void ResetDBInfo_Click(object sender, EventArgs e) { if (AdminPasswordTextBox.Text.Length < 6) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统管理员密码不能少于6位!');</script>"); return; } if (DatabaseTextBox.Text.Length == 0 && DBTypeDropDownList.SelectedValue == "SqlServer") { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>数据库名称不能为空!</script>"); return; } if (DBTypeDropDownList.SelectedIndex == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择数据库类型!');</script>"); return; } try { SiteConfigInfo __configinfo; try { __configinfo = SiteConfigs.GetConfig(); } catch { __configinfo = new SiteConfigInfo(); } __configinfo.AdministratorKey = Encrypt(AdminPasswordTextBox.Text); __configinfo.IsPasswordHashed = true; __configinfo.SiteName = WebsiteNameTextBox.Text; __configinfo.AdministratorName = AdminNameTextBox.Text; SiteConfigs.Serialize(__configinfo, Server.MapPath("~/Config/site.config")); Session["SystemAdminName"] = AdminNameTextBox.Text; Session["SystemAdminPwd"] = AdminPasswordTextBox.Text; } catch { } string setupDBType = SelectDB = DBTypeDropDownList.SelectedValue; DatabaseInfo dbi = new DatabaseInfo(); dbi.Server = ServerTextBox.Text; dbi.Database = DatabaseTextBox.Text; dbi.User = UserTextBox.Text; dbi.Password = PasswordTextBox.Text; dbi.DBFile = DBFileNameTextBox.Text; BaseConfigInfo bci = Installer.GenerateConnectionString(setupDBType, dbi); if (!SaveDBConfig(bci)) { ResetDBInfo.Enabled = false; Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>if(confirm('无法把设置写入\"db.config\"文件,系统将把文件内容显示出来,您可以将内容保存为\"db.config\",然后通过FTP软件上传到网站根目录下.. \\r\\n*注意:db.config位于网站Config目录下。\\r\\n\\r\\n如要继续运行安装,请按\"确定\"按钮.')){window.location.href='step4.aspx?isforceload=1';}else{window.location.href='step3.aspx';}</script>"); return; } if (bci.DBType == "Oracle" || bci.DBType == "MySql") { CreateNewDBCheckBox.Checked = false; } if (CreateNewDBCheckBox.Checked) { Exception ex = null; int ret = Installer.CreateDatabase(bci, out ex); if (ret == -1) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('数据库已经存在,请重新命名或去掉“创建新数据库”前的勾,使用已有数据库');</script>"); return; } if (ret == 0) { string exceptionMsgs = We7Helper.ConvertTextToHtml(ex.Message); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('数据库创建失败,错误原因:" + exceptionMsgs + "');</script>"); return; } } string msg = ""; if (!Installer.CheckConnection(bci, out msg)) { msg = We7Helper.ConvertTextToHtml(msg); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('连接数据库失败,请检查您填写的数据库信息。" + msg + "');</script>"); return; } else { Response.Redirect(Server.HtmlEncode(string.Format("step4.aspx?db={0}", setupDBType)), true); } }