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

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security 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是否已经存在,如果存在,就应该直接转向,不应该继续生成页面了。