1.在服務器上指定ASPx網頁,生成Html靜態頁1;
2.在服務器上執行ASPx網頁時在Page_Render事件裡將本頁面生成Html靜態頁2;
3.從指定連接獲取源代碼生成Html靜態頁3。其實這應該算網頁源代碼獲取方式了。
1.在服務器上指定ASPx網頁,生成Html靜態頁1
using system.Net;
using system.io;
system.io.streamwriter sw = new system.io.streamwriter(server.mappath("靜態頁1.Html"),false, system.text.encoding.getencoding("gb2312"));
system.web.httpcontext.current.server.execute("t.ASPx", sw);sw.close();
2.在服務器上執行ASPx網頁時在page_render事件裡將本頁面生成Html靜態頁2。
protected override void render(Htmltextwriter writer)
{ system.io.stringwriter Html = new system.io.stringwriter();
system.web.ui.htmltextwriter tw = new system.web.ui.htmltextwriter(Html);
base.render(tw);
system.io.streamwriter sw;
sw = new system.io.streamwriter(server.mappath("靜態頁2.htm"), false, system.text.encoding.default);
sw.write(Html.tostring());
sw.close();
tw.close();
response.write(Html.tostring());
}
3.從指定連接獲取源代碼生成Html靜態頁1。其實這應該算網頁源代碼獲取方式了。 //獲得指定鏈接的源代碼
string pageurl = "http://www.eshinfo.com/";
webrequest request = webrequest.create(pageurl);
webresponse response = request.getresponse();
stream resstream = response.getresponsestream();
streamreader sr = new streamreader(resstream, system.text.encoding.default);
string contentHtml = sr.readtoend();
resstream.close();
sr.close(); //寫入文件
system.io.streamwriter sw;
sw = new system.io.streamwriter(server.mappath("靜態頁生成方法3.htm"), false, system.text.encoding.default);
sw.write(contentHtml);
sw.close();