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("[email protected]", "test");//源郵件位址
3 mailMsg.To.Add(new MailAddress("[email protected]", "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);