ASP.NET 生成靜態(tài)頁面 實現(xiàn)思路
更新時間:2009年06月25日 13:32:44 作者:
網上的cms系統(tǒng)好多都是支持生成靜態(tài)的,大家在使用過程中,也肯定遇到了很多的問題,下面就是一些實現(xiàn)的原理,其實 asp,php,asp.net的原理都是差不多的。
1.首頁選擇HTML原型網頁
然后再該HTML網頁添加一些自認為特別的標記,已便到時候靜態(tài)化的時候系統(tǒng)能更精確的進行操作!
2.獲取HTML網頁代碼
我選擇的是通過FileUpload控件進行獲取靜態(tài)度頁面模型,進行保存!
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插入數(shù)據(jù)庫 已便使用時候提?。?
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 );
對模型頁面中預先 設置好的特別標記進行替換成我們需要動態(tài)更改的!
4.對動態(tài)更新后的HTML代碼進行文件進行保存 平把路徑存如數(shù)據(jù)庫方便調用
然后再該HTML網頁添加一些自認為特別的標記,已便到時候靜態(tài)化的時候系統(tǒng)能更精確的進行操作!
2.獲取HTML網頁代碼
我選擇的是通過FileUpload控件進行獲取靜態(tài)度頁面模型,進行保存!
復制代碼 代碼如下:
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插入數(shù)據(jù)庫 已便使用時候提?。?
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 );
對模型頁面中預先 設置好的特別標記進行替換成我們需要動態(tài)更改的!
4.對動態(tài)更新后的HTML代碼進行文件進行保存 平把路徑存如數(shù)據(jù)庫方便調用
您可能感興趣的文章:
- ASP.NET MVC3關于生成純靜態(tài)后如何不再走路由直接訪問靜態(tài)頁面
- 使用ASP.NET模板生成HTML靜態(tài)頁面的五種方案
- ASP.NET動態(tài)生成靜態(tài)頁面的實例代碼
- Asp.NET 生成靜態(tài)頁面并分頁的代碼
- Asp.Net生成靜態(tài)頁面的實現(xiàn)方法
- ASP.NET MVC生成靜態(tài)頁面的方法
- asp.net生成Excel并導出下載五種實現(xiàn)方法
- asp.net(C#) 生成隨機驗證碼的代碼
- ASP.net(c#)生成條形碼 code39條碼生成方法
- asp.net C#生成和解析二維碼的實例代碼
- Asp.net生成Excel文件并下載(更新:解決使用迅雷下載頁面而不是文件的問題)
- ASP.NET編程簡單實現(xiàn)生成靜態(tài)頁面的方法【附demo源碼下載】
相關文章
使用Fiddler調試visual studion多個虛擬站點的問題分析
本篇文章小編為大家介紹,使用Fiddler調試visual studion多個虛擬站點的問題分析。需要的朋友參考下2013-04-04解決asp.net mvc UpdateModel更新對象后出現(xiàn)null問題的方法
這篇文章主要介紹了解決asp.net mvc UpdateModel 更新對象后出現(xiàn)null問題的方法,需要的朋友可以參考下2015-11-11深入解析.NET 許可證編譯器 (Lc.exe) 的原理與源代碼剖析
許可證編譯器 (Lc.exe) 的作用是讀取包含授權信息的文本文件,并產生一個可作為資源嵌入到公用語言運行庫可執(zhí)行文件中的 .licenses 文件2013-07-07asp.net中使用cookie與md5加密實現(xiàn)記住密碼功能的實現(xiàn)代碼
雖然.net內置了登陸控件,有記住密碼的功能,但還是想自己實踐一下,以下代碼主要應用了COOKIE,包括安全加密的過程等2013-02-02使用Spring.Net框架實現(xiàn)多數(shù)據(jù)庫
這篇文章介紹了Spring.Net框架實現(xiàn)多數(shù)據(jù)庫的方法,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-03-03