1.. System.Net.WebClient wc = new System.Net.WebClient();
wc.DownloadFile(url,path);
上面方法很簡單,之間訪問這個URL地址,就會產生一個HTML頁面,之後直接訪問此HTML頁面,會快很多
還有的比如 httprequest類
2.原理同上
/// <summary>
/// 轉換成靜態HTML
/// </summary>
/// <param name="path">動態頁面路徑 如Aritcle.aspx?id=1 </param>
/// <param name="outpath">生成的HTML文件路徑 </param>
public void transHtml(string path, string outpath)
{
Page page = new Page();
StringWriter writer = new StringWriter();
page.Server.Execute(path, writer);
FileStream fs;
if (File.Exists(page.Server.MapPath("") + "//" + outpath))
{
File.Delete(page.Server.MapPath("") + "//" + outpath);
fs = File.Create(page.Server.MapPath("") + "//" + outpath);
}
else
{
fs = File.Create(page.Server.MapPath("") + "//" + outpath);
}
byte[] bt = Encoding.Default.GetBytes(writer.ToString());
fs.Write(bt, 0, bt.Length);
fs.Close();
}
不過我感覺還是第一種比較簡單,第二種還是輸入一個URL,進行訪問,得到的內容保存爲HTML文件。