Asp.net实现静态页(1)-添加新闻生成静态页
//当后台添加或编辑信息后执行如下代码:
string html = string.Empty;
try
{
//据体意思:根据你更新及编辑过新闻的URL,然后来读取他的源码,html==源码
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.xczp.com/");
//设置连接超时时间
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
Encoding encoding = Encoding.UTF8;
StreamReader streamReader = new StreamReader(streamReceive, encoding);
html = streamReader.ReadToEnd();
}
catch { }
//据体意思:利用你所获得的源码,导出为 .html 页面,从而生成静态页
string URL = Server.MapPath("~\\") + "index.html";
Encoding code = Encoding.GetEncoding("gb2312");
StreamWriter sw = new StreamWriter(URL, false, code);
sw.Write(html);
sw.Flush();
上面可能说的不是太清楚,有的地方可能不是太好。请大家指点出来,交流交流,共同进步!
接下来我会继续研究下去的,一定要让ASP.NET生成静态页搞定。呵,如果大家有好的建议及方法,写出来大家一起学习!