ASP.NET頁面靜態(tài)化四步走
ASP.NET頁面靜態(tài)化***步:首頁選擇HTML原型網(wǎng)頁
然后再該HTML網(wǎng)頁添加一些自認為特別的標記,已便到時候靜態(tài)化的時候系統(tǒng)能更精確的進行操作!
ASP.NET頁面靜態(tài)化第二步:獲取HTML網(wǎng)頁代碼
我選擇的是通過FileUpload控件進行獲取靜態(tài)度頁面模型,進行保存!
- if (FileUpload1.PostedFile.FileName == "")
- {
- Response.Write("");
- return;
- }
- if ((FileUpload1.FileName.LastIndexOf(".") != "htm") ||
- (FileUpload1.FileName.LastIndexOf(".") != "html"))
- {
- Response.Write("");
- return;
- }
- System.Text.Encoding ec = System.Text.Encoding.
- GetEncoding("gb2312");//指定編碼格式
- System.IO.StreamReader sr = new System.IO.StreamReader
- (FileUpload1.PostedFile.FileName, ec);
- string strHTML =Convert.ToString(sr.ReadToEnd());
- strHTML=FormatStr(strHTML); //格式化HTML代碼后,
- 將此strHTML插入數(shù)據(jù)庫 已便使用時候提取!
- sr.Close();
- //貼上格式化HTML方法代碼
- ///
- /// 格式 化 HTML
- ///
- ///
- ///
- private string FormatStr(string str)
- {
- string strContent = str.Replace("<", "<");
- strContent = strContent.Replace(">", ">");
- //strContent = strContent.Replace(chr(13),"
- ");
- strContent = strContent.Replace(" ", "
- ");
- strContent = strContent.Replace(" ", " ");
- strContent = strContent.Replace("[isOK]", "
- strContent = strContent.Replace("[red]", "");
- strContent = strContent.Replace("[big]", "");
- strContent = strContent.Replace("[/isOK]", ">");
- strContent = strContent.Replace("[/b]", "");
- strContent = strContent.Replace("[/red]", "");
- strContent = strContent.Replace("[/big]", "");
- return strContent;
- }
ASP.NET頁面靜態(tài)化第三步:提取先前保存過的HTML頁面模型
然后通過 string.Replace(char oldstring,char newstring );
對模型頁面中預先 設置好的特別標記進行替換成我們需要動態(tài)更改的!
ASP.NET頁面靜態(tài)化第四步:對動態(tài)更新后的HTML代碼進行文件進行保存 平把路徑存如數(shù)據(jù)庫方便調用!
【編輯推薦】