zoukankan      html  css  js  c++  java
  • .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;
            }
        }

  • 相关阅读:
    Java 类加载机制详解
    设置菜单栏中和地址栏对应的活动项高亮
    相交链表
    二叉树的最大深度 递归
    买卖股票的最佳时机 一次遍历
    对称二叉树 递归&迭代
    二叉树的中序遍历 --采用递归
    最大子序和 动态规划
    前K个高频单词 字符型 用Hash表+Collections排序 + 优先队列
    加一 (运用取余数)
  • 原文地址:https://www.cnblogs.com/zhanlang/p/1875776.html
Copyright © 2011-2022 走看看