zoukankan      html  css  js  c++  java
  • ASP.NET生成静态页面

    /// <summary>
            /// 生成静态页面
            /// </summary>
            /// <param name="webUrl">url</param>
            /// <param name="savePath">保存本地的路径</param>
            /// <returns></returns>
            public static void AppendHTML(string webUrl, string savePath)
            {
                Dictionary<string, string> dict = new Dictionary<string, string>(1);
                dict.Add(webUrl, savePath);
                AppendHTML(dict);
            }
            public static void AppendHTML(Dictionary<string, string> dict)
            {
                WebClient client = new WebClient();
                client.Credentials = CredentialCache.DefaultCredentials;  //获取或设置用于对向Internet资源的请求进行身份验证的网络凭据。
                HttpContext context = HttpContext.Current;
                foreach (KeyValuePair<string, string> pair in dict)
                {
                    string url = pair.Key.StartsWith("http://") ? pair.Key : "http://" + context.Request.ServerVariables["HTTP_HOST"] + pair.Key;
                    string path = pair.Value;
                    path = Path.GetDirectoryName(AppRuntime.MapPath(path));
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    byte[] buffer = client.DownloadData(url);
                    long length = buffer.LongLength;
                    if (length > int.MaxValue)
                    {
                        throw new IOException("FileTooLong2GB");
                    }
                    int count = (int)length;
                    using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write))
                    using (BinaryWriter writer = new BinaryWriter(stream, Encoding.Default))
                    {
                        writer.Write(buffer, 0, count);
                    }
                }
                client.Dispose();
            }
    

  • 相关阅读:
    Docker 使用Calico插件配置网络
    Fluentd插件rewrite-tag-filter介绍
    Fluentd Regexp patterns
    gdb 打印数据结构
    g++ -g
    《100-gdb-tips》——查看调用堆栈
    dbghelp.dll 定位异常奔溃信息
    debug skill:烫烫烫屯屯屯
    sizeof()和strlen()的区别
    指针和引用的区别
  • 原文地址:https://www.cnblogs.com/Googler/p/1913870.html
Copyright © 2011-2022 走看看