CMS系統關鍵技術點總結(UrlRewrite、批量靜態化、發送郵件)

1.UrlRewritehtml

 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.批量靜態化url

 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.發送郵件spa

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);    
相關文章
相關標籤/搜索