惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
博客园 - 【当耐特】
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
小众软件
小众软件
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
MyScale Blog
MyScale Blog

博客园 - 酷咖啡

收藏:精妙SQL语句 用户中心 - 博客园 博文阅读密码验证 - 博客园 web2.0配色收集 也谈C#中的反射用法 C#访问修饰符 C#中相等的判断 [LoveCherry]一步一步学Linq to sql系列文章 [LoveCherry]无废话C#设计模式系列文章 .Net常用资源收集 Some word in English about Company website Reflection,Regular Expression,Threading,IO,AppDomain,Web Service/Remoting Service,ORM 收藏:笔记本得理器型号规格 如何让虚拟目录里面的webconfig不继承网站[转] 刚刚用上了百度Hi 自定义可绑定数据的业务对象实体和强类型 数据库设计的5种常见关系 [收集]visual studio文件扩展名 说说最近的工作
Asp.net 2.0 网站首页生成静态的方法
酷咖啡 · 2008-03-27 · via 博客园 - 酷咖啡

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

将以上上函数数加如到你要生成静太文件的页面里,
函数从载了,Render函数 作用是把页面的 html文本截下来,保存到文件里,
进一步的可以去看一下asp.net页面生命过程.
静态页面的生成

protected override void Render(HtmlTextWriter writer) {
     StreamWriter r
=new StreamWriter(Server.MapPath(StaticFileName),
           
false,System.Text.Encoding.UTF8);  //StaticFileName是html文件名
     HtmlTextWriter h=new HtmlTextWriter(r);
     
base.Render(h); 
     r.Close();
     h.Close();
     Response.Redirect(StaticFileName);
}

然后在同一aspx的pageLoad事件中判断StaticFileName是否已经存在,如果存在,就应该直接转向,不应该继续生成页面了。