ASPX是一種非常流行的動態網頁格式,動態網頁的特點之一是信息交換、更新及時、頁面文件少、開發速度快,錯新技術頻道小編將和你分享ASP.NET 生成靜態頁面 實現思路。
1.首頁選擇HTML原型網頁
然后再該HTML網頁添加一些自認為特別的標記,已便到時候靜態化的時候系統能更精確的進行操作!
2.獲取HTML網頁代碼
我選擇的是通過FileUpload控件進行獲取靜態度頁面模型,進行保存!
?
復制代碼 代碼如下:
?
if (FileUpload1.PostedFile.FileName == "")
{
Response.Write("<script>alert('請確定您是否選擇了網頁')</script>");
return;
}
if ((FileUpload1.FileName.LastIndexOf(".") != "htm") || (FileUpload1.FileName.LastIndexOf(".") != "html"))
{
Response.Write("<script>alert('請確定您是否選擇了網頁')</script>");
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插入數據庫 已便使用時候提取!
sr.Close();
//貼上格式化HTML方法代碼
/// <summary>
/// 格式 化 HTML
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private string FormatStr(string str)
{
string strContent = str.Replace("<", "<");
strContent = strContent.Replace(">", ">");
//strContent = strContent.Replace(chr(13),"<br>");
strContent = strContent.Replace("/r", "<br>");
strContent = strContent.Replace(" ", "?");
strContent = strContent.Replace("[isOK]", "<img src=");
strContent = strContent.Replace("[b]", "<b>");
strContent = strContent.Replace("[red]", "<font color=CC0000>");
strContent = strContent.Replace("[big]", "<font size=7>");
strContent = strContent.Replace("[/isOK]", "></img>");
strContent = strContent.Replace("[/b]", "</b>");
strContent = strContent.Replace("[/red]", "</font>");
strContent = strContent.Replace("[/big]", "</font>");
return strContent;
}
3.提取先前保存過的HTML頁面模型
然后通過 string.Replace(char oldstring,char newstring );
對模型頁面中預先 設置好的特別標記進行替換成我們需要動態更改的!
4.對動態更新后的HTML代碼進行文件進行保存 平把路徑存如數據庫方便調用
以上這些是錯新技術頻道小編給大家介紹的ASP.NET 生成靜態頁面 實現思路,閱讀了這篇文章,大家是否對這些知識有所了解了?