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 @   Sunnier  阅读(790)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
点击右上角即可分享
微信分享提示