zoukankan      html  css  js  c++  java
  • C#加载前生成静态网页

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.IO;

    namespace test
    {
    public class PageCreateRenderPage : System.Web.UI.Page
    {
    public string strFileName = "default.html";

    public string redirectURL = null;

    public PageCreateRenderPage() { }

    protected override void Render(HtmlTextWriter writer)
    {
    TextWriter tw = new StringWriter();
    base.Render(new HtmlTextWriter(tw));
    tw.Close();
    string html = tw.ToString();
    int urllen = Request.Url.AbsoluteUri.LastIndexOf('/');
    string url = Request.Url.AbsoluteUri.Substring(urllen + 1);
    strFileName = Server.MapPath(".") + "/" + url.Split('.')[0]+".html";
    writeHtml(strFileName, html);
    Response.Redirect(url.Split('.')[0]+".html");
    }

    public static void writeHtml(string filmname, string html)
    {
    System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312");
    string htmlfilename = filmname;
    string str = html;
    StreamWriter sw = null;
    // 写文件
    try
    {

    sw = new StreamWriter(htmlfilename, false, code);

    sw.Write(str);

    sw.Flush();

    }

    catch (Exception ex)
    {

    HttpContext.Current.Response.Write(ex.Message);

    HttpContext.Current.Response.End();

    }

    finally
    {

    sw.Close();

    }

    }
    }
    }

  • 相关阅读:
    window servet 2012 r2 配置php服务器环境
    thinkphp5 input坑
    tp5命名空间补充
    cookie和session
    thinkphp5.0 模型的应用
    JavaScript--计时器
    Runtime Only VS Runtime+Compil
    Object.keys
    [LeetCode 17]电话号码的字母组合
    数组里的字符串转换成数字或者把数字转换成字符串
  • 原文地址:https://www.cnblogs.com/codeloves/p/3337443.html
Copyright © 2011-2022 走看看