zoukankan
html css js c++ java
页面执行时生成静态文件的方法
protected
override
void
Render(HtmlTextWriter writer)
{
if
(EnableStaticFile)
{
if
(transferToHtml)
return
;
string
authorPath
=
Server.MapPath(
"
/authors/
"
+
GetUrlPath(authorID)
+
"
.html
"
);
string
authorDir
=
Path.GetDirectoryName(authorPath);
if
(
!
Directory.Exists(authorDir))
{
Directory.CreateDirectory(authorDir);
}
TextWriter ioWriter
=
null
;
HtmlTextWriter hioWriter
=
null
;
try
{
ioWriter
=
new
StreamWriter(authorPath,
false
, Response.ContentEncoding);
hioWriter
=
new
HtmlTextWriter(ioWriter);
base
.Render(hioWriter);
}
catch
(Exception)
{ }
finally
{
if
(ioWriter
!=
null
) ioWriter.Close();
if
(hioWriter
!=
null
) hioWriter.Close();
}
}
base
.Render(writer);
}
如上代码,重写Page的Render方法,新建一个指向文件的HtmlTextWriter在页面输出之前执行base.Render(txtWriter)即可。非常简单。
查看全文
相关阅读:
【转】每天一个linux命令(41):ps命令
【转】每天一个linux命令(40):wc命令
【转】每天一个linux命令(39):grep 命令
【转】每天一个linux命令(38):cal 命令
【转】每天一个linux命令(37):date命令
【转】每天一个linux命令(36):diff 命令
【转】每天一个linux命令(35):ln 命令
【转】每天一个linux命令(34):du 命令
诗词、对联名句(千古名帖)
诗词、对联名句(千古名帖)
原文地址:https://www.cnblogs.com/yukaizhao/p/dot_net_generate_static_file.html
最新文章
超好用的plsql设置
Eclipse 控制console
Linux系统入门学习:在curl中设置自定义的HTTP头
tomcat7源码编译过程以及问题解决
Eclipse 快捷键
securecrt 用心跳保持连接
关于plsql连接oracle数据库session失效时间设置
Starting nagios:This account is currently not available.
android 4.4最新官方源代码下载
为线程绑定CPU
热门文章
怎样更好的设计android图标,拉伸不变形等等系列长处,并且减小apk大小
范冰冰李晨爱巢疑曝光 高科技智能停车场甩狗仔
一个程序猿的遗嘱么?
使用Spring Mvc 转发 带着模板 父页面 之解决方法 decorators.xml
python编程练习
【ios开发学习
随机颜色文件 用的时候直接推进去好方便
算法之动态规划
【转】每天一个linux命令(43):killall命令
【转】每天一个linux命令(42):kill命令
Copyright © 2011-2022 走看看