.net生成静态页
如果你全站生成不了静态页,但是你可以把首页生成静态页,只要短短几行代码就可以搞定,这样的话,最少你的网站首页加载起来要快多了,不说了 直接代码:
protected override void Render(HtmlTextWriter writer)
{
string filename = ""
+ DateTime.Now.Year
+ DateTime.Now.Month
+ DateTime.Now.Day
+ DateTime.Now.Hour
+ DateTime.Now.Minute
+ DateTime.Now.Second
+ DateTime.Now.Millisecond + ".htm";
try
{
string newpath = Server.MapPath(".") + "\\" + filename;
//string newpath = Server.MapPath("newfile") + "\\" + filename;
FileStream fs = File.Create(newpath);
fs.Close();
//File.Create(Server.MapPath("newfile") + "\\" + filename);
StreamWriter r = new StreamWriter(newpath, false, System.Text.Encoding.UTF8);
HtmlTextWriter h = new HtmlTextWriter(r);
base.Render(h);
Response.Redirect(newpath);
r.Close();
h.Close();
}
catch (Exception error)
{
throw error;
}
}