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

1.UrlRewrite

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

2.批量静态化

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

3.发送邮件

1             MailMessage mailMsg = new MailMessage();//两个类,别混了 引入System.Web这个Assembly
2             mailMsg.From = new MailAddress("jayjay@ibook.com", "test");//源邮件地址 
3             mailMsg.To.Add(new MailAddress("test2@qq.com", "jayjay"));//目的邮件地址。可以有多个收件人
4             mailMsg.Subject = "你好";//发送邮件的标题 
5             mailMsg.Body = "你好";//发送邮件的内容 
6             SmtpClient client = new SmtpClient("10.170.9.80");
7             client.Credentials = new NetworkCredential("jayjay", "123");
8             client.Send(mailMsg);    

 

posted @ 2015-04-05 23:03  Sunnier  阅读(769)  评论(0编辑  收藏  举报