现在,谈到生成静态页面,大家比较熟悉的是,模板替换,服务器重写,伪静态。
今天找到了另一中方法:
这种方法的优点是:不需要模板,甚至说是完全自动化。缺点是:性能可能不好(我没有测试过他的性能)
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Net;
- using System.IO;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- HttpWebRequest request = (HttpWebRequest)(WebRequest.Create("http://www.mypid.cn/ProductsView.asp?id=282"));
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- if (response.StatusCode == HttpStatusCode.OK)//因为发送的是HTTP请求,所以可以强制转换成HttpWebResponse,用以获取它的StatusCode,这是表示请求状态
- {
- Stream resStream = response.GetResponseStream();
- StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
- string tempCode = sr.ReadToEnd();
- ///Response.Write(tempCode);
- ///此处保存字符串到Html文件,此处省略。
- resStream.Close();
- sr.Close();
- }
- }
- }
文章来自:http://blog.csdn.net/hongsejiaozhu/article/details/4259966