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();