首页静态化

我用过的首页静态化手段自我感觉还是最下面的这种方式好(力荐)。

常用的首页静态化手段有:缓存、模板静态化、伪静态等。

缓存:由于个人技术有限应用起来不是很好。

模板静态化:由于首页内容繁多,做起来很烦。这种方式只适合应用于首页内容较少的。

伪静态:容易造成CPU超负荷。

下面我要说的一种超简单的方法就是重写Render这个方法把首页内容写进index.htm网页中。

protected override void Render(HtmlTextWriter writer)
    {
        System.IO.StringWriter html = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter tw = new HtmlTextWriter(html);
        base.Render(tw);
        System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("index.htm"), false, System.Text.Encoding.Default);
        sw.Write(html.ToString());
        sw.Close();
        tw.Close();

//如何在静态页中更新信息,这就需要用户自己更新。在页面上方添加

        这儿写上Response.Redirect("index.htm");//表明每次加载首页动态页时都是重写index.aspx页面重写后重定向到Index.htm
     }

 

posted @ 2012-04-25 21:49  aspneteye  阅读(240)  评论(0编辑  收藏  举报