zoukankan      html  css  js  c++  java
  • 全站生成静态文件的通用方法

    其实,生成网站纯静态文件原理很简单,我先介绍一种我自己的生成方法,就是通过url地址来生成静态,注意:url地址必须带上http://

    代码如下:

     

        /// <summary>

        /// 创建html文件

        /// </summary>

        /// <param name="page_url">URL地址</param>

     

       /// <param name="path">生成到哪个目录的物理路径地址</param>

     

        public static void CreateSingleHtml(string page_url,string path)

        {

            string pageurl = site_url + page_url;

            System.Net.WebRequest request = WebRequest.Create(pageurl);

            WebResponse response = request.GetResponse();

            Stream resstream = response.GetResponseStream();

            StreamReader sr = new StreamReader(resstream, System.Text.Encoding.UTF8);

            string contenthtml = sr.ReadToEnd();

            resstream.Close();

            sr.Close();//写入文件   

            System.IO.StreamWriter sw;

            sw = new System.IO.StreamWriter(path, false, System.Text.Encoding.UTF8);

            sw.Write(contenthtml);

            sw.Close();  

        }

    我测试过了,绝对可用。

    比如:

    page_url="http://www.xxx.com/about.aspx";

    path="Server.MapPath("/html/about.html")";

    这样就会在根目录的html目录下生成about.html文件

    转载请注明出处:赣州网站建设

  • 相关阅读:
    模拟tap事件和longTap事件
    jquery工具方法总结
    outline:0与outline:none区别
    babel吐槽
    兼容ie8 rgba()写法
    git删除文件夹
    css简写总结
    回调函数实例—(二)
    回调函数的那些事儿(转载)
    回调函数好文章汇总
  • 原文地址:https://www.cnblogs.com/yujiubo/p/2759844.html
Copyright © 2011-2022 走看看