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);    

 

转载于:https://www.cnblogs.com/sunniest/p/4395003.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值