CMS系统关键技术点总结(UrlRewrite、批量静态化、发送邮件)

1.UrlRewrite

         protected void Application_BeginRequest(object sender, EventArgs e)
{
//将请求的ShowArticle页面进行url重写
string url = HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath;
Match match = Regex.Match(url, @"~/Article/ShowArticle-(\d+).aspx");
if (match.Success)
{
long id = Convert.ToInt64(match.Groups[].Value);
HttpContext.Current.RewritePath("~/Article/ShowArticle.aspx?id=" + id);
}
}

2.批量静态化

             List<T_Articles> list = new T_ArticlesBLL().GetModelList("");
foreach (T_Articles model in list.ToArray())
{
WebClient wb = new WebClient();
wb.Encoding = Encoding.UTF8;
string url = string.Format("http://{0}/Article/ShowArticle-{1}.aspx",Request.Url.Authority,model.Id);
try
{
wb.DownloadFile(url,Server.MapPath(string.Format("~/Article/ShowArticle-{0}.html", model.Id)));
}
catch(WebException wbex){
CommonHelper.showMsg(Page, "下载id号为" + model.Id + "的页面时出错!" + wbex.Message);
log.Error("下载id号为" + model.Id + "的页面时出错!" + wbex.Message);
}
}

3.发送邮件

             MailMessage mailMsg = new MailMessage();//两个类,别混了 引入System.Web这个Assembly
mailMsg.From = new MailAddress("jayjay@ibook.com", "test");//源邮件地址
mailMsg.To.Add(new MailAddress("test2@qq.com", "jayjay"));//目的邮件地址。可以有多个收件人
mailMsg.Subject = "你好";//发送邮件的标题
mailMsg.Body = "你好";//发送邮件的内容
SmtpClient client = new SmtpClient("10.170.9.80");
client.Credentials = new NetworkCredential("jayjay", "");
client.Send(mailMsg);
上一篇:Yii2请求,报400错误


下一篇:[自考]C++中一些特殊用法 2016-10-16 22:12 318人阅读 评论(30) 收藏