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