zoukankan      html  css  js  c++  java
  • ASP.NET静态化方法

    直接通过访问页面获取html代码实现静态化

    突然想到一个静态化页面的方法:直接保存源代码即可。

    模拟浏览器访问,获得源码,写入文件。不知道是否存在安全风险;各位大神请指点:

    注意

    1、资源使用绝对路径,包括图片,JS,CSS和其他资源。

    2、html文件可能需要统一管理(按目录/日期分类保存,使用了觉得路径可以避免资源失效)。

    示例代码

            string file = Server.MapPath("/") + "index.html";
            Response.Write(file);
            //Response.End();
            //return;
            WebClient web = new WebClient();
            byte[] buffer = web.DownloadData("http://localhost:81/");
            string result = Encoding.UTF8.GetString(buffer);
            FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
            sw.Write(result);
            sw.Flush();
            sw.Close();
            fs.Close();
            Response.Redirect("http://localhost:81/index.html");
  • 相关阅读:
    redis集群
    鉴权方案选择
    spring mvc 自定义handler不拦截静态资源
    servlet3
    压测工具 ab jmeter
    死锁产生的原因
    缓存方案:本地guavaCache, 远程redis?
    使用spring boot admin
    groovy使用小记
    python--面试题01
  • 原文地址:https://www.cnblogs.com/shya/p/3586417.html
Copyright © 2011-2022 走看看