將ASPX檔案生成HTML檔案

2021-04-03 00:15:04 字數 3984 閱讀 8906

方案1:

///

/// 傳入url返回網頁的html**

///

/// url

///

public static  string geturltohtml(string url)

// get the response stream.

system.io.stream respstream  = wresp.getresponsestream();

// dim reader as streamreader = new streamreader(respstream)

system.io.streamreader reader = new system.io.streamreader(respstream, system.text.encoding.getencoding("gb2312"));

return  reader.readtoend();

}catch(system.exception ex)

return "";

}你可以用這個函式獲取網頁的客戶端的html**,然後儲存到.html檔案裡就可以了。

像阿里巴巴的頁面也全部是html的,估計用的是位址對映的功能

關於位址對映可參考:http://www.easewe.com/article/showarticle.aspx?article=131

可以看看這個頁面,分析一下他的「競價倒計時」功能

asp.net生成靜態html頁

在asp中實現的生成靜態頁用到的filesystemobject物件!

在.net中涉及此類操作的是system.io

以下是程式** 注:此**非原創!參考別人**

此函式放在conn.cs基類中了

在新增新聞的**中引用 注:工程名為hover

if(hover.conn.writefilethis.title.text.tostring),this.content.text.tostring),this.author.text.tostring)))

else

模板頁text.html**

code:  

showarticle

biaoti

content

author

biaoti

content

author

提示新增成功後會出以當前時間為檔名的html檔案!上面只是把傳遞過來的幾個引數直接寫入了html檔案中,在實際應用中需要先新增資料庫,然後再寫入html檔案

方案3:

給乙個客戶端參考的例子(sj)

它的作用在於以客戶端的方式獲取某個頁面的**,然後可以做為其他用途,本例是直接輸出

方案4:學csdn一樣。用xml儲存資料,模版xsl也只有乙個檔案。

使用xml來儲存資料,使用xsl來定義模板並且生稱資料。可以通過xsl來很方便的在客戶端或者服務段顯示資料。如果要生成靜態葉面那更簡單了。去查一下.net的xml類包問題解決。

優點:可以方便快速轉換成你想要的格式和內容。

缺點:需要學習更多的內容,不好入門。

方案5:

思路 1. 利用如dw-mx這樣的工具生成html格式的模板,在需要新增格式的地方加入特殊標記(如$htmlformat$),動態生成檔案時利用**讀取此模板,然後獲得前台輸入的內容,新增到此模板的標記位置中,生成新檔名後寫入磁碟,寫入後再向資料庫中寫入相關資料。

2. 使用後台**硬編碼html檔案,可以使用htmltextwriter類來寫html檔案。

優點 1. 可以建立非常複雜的頁面,利用包含js檔案的方法,在js檔案內加入document.write()方法可以在所有頁面內加入如頁面頭,廣告等內容。

2. 靜態html檔案利用ms windows2000的index server可以建立全文搜尋引擎,利用asp.net可以以datatable的方式得到搜尋結果。而win2000的index服務無法查詢xml檔案的內容。如果包括了資料庫搜尋與index索引雙重查詢,那麼此搜尋功能將非常強大。

3. 節省伺服器的負荷,請求乙個靜態的html檔案比乙個aspx檔案伺服器資源節省許多。

缺點 因此這裡採用的是第一種思路

示列**

1.定義(template.htm)html模板頁面

//---------------------讀html模板頁面到stringbuilder物件裡----

string format=new string[4];//定義和htmlyem標記數目一致的陣列

stringbuilder htmltext=new stringbuilder();

try

using (streamreader sr = new streamreader("存放模板頁面的路徑和頁面名"))

string line;

while ((line = sr.readline()) != null)

sr.close();

catch

response.write("<script>alert('讀取檔案錯誤')</script>");

//---------------------給標記陣列賦值------------

format[0]="background="bg.jpg"";//背景

format[1]= "#990099";//字型顏色

format[2]="150px";//字型大小

format[3]= "<marquee>生成的模板html頁面</marquee>";//文字說明

//----------替換htm裡的標記為你想加的內容

for(int i=0;i<4;i++)

htmltext.replace("$htmlformat["+i+"]",format[i]);

//----------生成htm檔案------------------――

try

using(streamwriter sw=new streamwriter("存放路徑和頁面名",false,system.text.encoding.getencoding("gb2312")))

sw.writeline(htmltext);

sw.flush();

sw.close();

catch

response.write ("the file could not be wirte:");

小結 用此方法可以方便的生成html檔案。程式使用了是迴圈替換,因此對需替換大量元素的模板速度非常快。

動態生成aspx檔案

動態生成aspx檔案及相應的cs檔案。using system using system.data using system.configuration using system.web using system.web.security using system.web.ui using syst...

aspx 生成HTML 靜態頁

cs 頁 using system using system.data using system.configuration using system.collections using system.web using system.web.security using system.web.ui...

Html檔案轉換為Aspx檔案後發現樣式丟失或失效

css中中文注釋導致aspx頁面樣式出錯 今天遇到乙個很奇怪的問題,網頁設計把頁面用層布局 發給我們以後,ie6下,靜態html頁面正常顯示,弄到vs裡,副檔名改為aspx後頁面就全變臉了,樣式應用不上,布局錯誤 後同事從網上看到是因為css中新增了中文注釋引起的,刪除css中的中文注釋,頁面正常顯...