zoukankan      html  css  js  c++  java
  • 静态页生成

    一、什么是静态页生成

     静态页是实际存在的,无需再服务器中编译,直接加载到客户端浏览器。

    静态页生成就是从数据库中数据读取出来,按一定的格式生成的页面,放在服务器磁盘中。

    二、为什么要生成静态页

     因为客户端请求过来,服务端得根据客户端请求内容,从数据库中读取数据,在生成字符串响应给客户端,对于比较经常被浏览的页面,会大大加重数据库的负担。所以可以把常被浏览的页面,可以做成静态页面。

    而且想后台挂掉了。静态页面也能正常的访问。

    比如首页。网站的门户。所以可以把首页生成静态页。

    三、有什么劣势

    占用了服务器的存储空间

    四、怎么生成静态页

    1 //读取模板页
    2 string templateHtml = File.ReadAllText(HttpContext.Current.Server.MapPath("/Template/BookTemplate.html"));
    3 //替换占位符
    4 string html = templateHtml.Replace("$title", model.Title).Replace("$msg", model.ContentDescription).Replace("$bookId", model.Id.ToString());
    5 //创建静态页存储的文件夹
    6 string direction = HttpContext.Current.Server.MapPath("/StaticPage/" + model.PublishDate.Year + "/" + model.PublishDate.Month + "/" + model.PublishDate.Day + "/");
    7 Directory.CreateDirectory(Path.GetDirectoryName(direction));
    8 //生成静态页
    9 File.WriteAllText(dir + model.Id + ".html", html, Encoding.UTF8);
  • 相关阅读:
    批处理
    命名规则
    注释
    HTML DOM属性
    OLTP
    修改HTML元素
    HTML
    工具资源系列之给虚拟机装个centos
    工具资源系列之给虚拟机装个windows
    工具资源系列之给mac装个虚拟机
  • 原文地址:https://www.cnblogs.com/since87/p/3168497.html
Copyright © 2011-2022 走看看