首页 .NET/Web 如何将aspx页面动态生成静态页面.html

如何将aspx页面动态生成静态页面.html

作者:胡同里的砖头 围观群众:712 更新于:2013-12-19

如果要把主页Index.aspx 生成静态页面 Index.html后输出会提高别人的访问速度.

发布网站时,发布Index.html,每次更新主页内容后,重新加载Index.aspx,就能自动刷新静态页面Index.html的内容!

方法是在Index.aspx.cs的后台代码中写入以下函数:

  1. //把动态页面.aspx 生成静态页面.html   
  2.         protected override void Render(HtmlTextWriter writer)  
  3.         {  
  4.             System.IO.StringWriter html = new System.IO.StringWriter();  
  5.             System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(html);  
  6.             base.Render(tw); System.IO.StreamWriter sw;  
  7.             sw = new System.IO.StreamWriter(Server.MapPath("Index.html"), false, System.Text.Encoding.Default);  
  8.             sw.Write(html.ToString()); sw.Close(); tw.Close(); Response.Write(html.ToString());  
  9.         }  

  • 本文标题: 如何将aspx页面动态生成静态页面.html
  • 文章分类:【.NET/Web】
  • 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
留言评论
站点声明:
1、本站【胡同里的砖头】个人博客,借鉴网上一些博客模板,取其各优点模块自行拼装开发,本博客开发纯属个人爱好。
2、所有笔记提供给广大用户交流使用,可转载,可复制,纯个人开发所遇问题锦集记录使用
Copyright © huzlblog.com All Rights Reserved. 备案号:苏ICP备2021056683号-8