环境:Microsoft .NET Framework SDK v1.1
------------------------------------------------------------------------
biaoti ASP.Net生成静态HTML页! 2004-06-01 13:36 Kriss
我找到我想用的方法了:
using System.Web.Hosting; WebHost host = (WebHost)ApplicationHost.CreateApplicationHost( typeof(WebHost), name, path); public void DoRequest(string page, string query, TextWriter writer) { HttpRuntime.ProcessRequest(new SimpleWorkerRequest(page, query, writer)); } 这样我就可以直接把一个ASPX文件产生HTML文件了 FileStream fs = File.Open("Default.htm"); host.DoRequest("Default.aspx",string.Empty,fs); ASP生成静态网页的方法
<!--#include file="conn.asp"--> οnmοuseup="" else if i=rs.recordcount then menutype="menu3" listtype="list1" οnmοuseup=" onMouseUp=change1('a"&rs("id")&"','b"&rs("id")&"');" else menutype="menu1" listtype="list" οnmοuseup=" onMouseUp=change2('a"&rs("id")&"','b"&rs("id")&"');" end if menuname=rs("menuname") end if str=str+" |
"&menuname&" |
"+chr(13) menu(rs("id")) str=str+" |
rs.close
set rs=nothing
end function
menu(0)
set fso=server.CreateObject("scripting.filesystemobject")
set f1=fso.opentextfile(server.MapPath("demo.htm"),2,true)
f1.write("")
f1.write("")
f1.write("
f1.write("")
f1.write("哈哈~~~!这回速度超快了吧?")
f1.write("")
f1.write("")
f1.write("")
f1.write("")
f1.write("")
f1.write("")
f1.write(" http://asp2004.net提供最新下载《 管理》
")
f1.write(str)
f1.write("")
f1.write("")
f1.close
set fso=nothing
response.Redirect("demo.htm")
%>
转载请注明:转自http://goaler.xicp.net
FSO生成静态HTML文件的时候替换模板标签一直是一个很麻烦的问题,至少我是这么认为的,还要别外做一个模板,麻烦!,我今天看见有一个方法可以解决这个问题
如一个正常的index.asp页面,并且用ASP代码调出数据库中的内容,另建一个makehtml.asp的页面,加入一个textarea域,假设为name="body",将index.asp在textarea里调出来,如:
<!--#include file="index.asp"-->,将这个textarea包含在表单中,在接收表单页用创建FSO对象,如下生成index.html文件!
filename="../index.html"
if request("body")<>"" then
set fso = Server.CreateObject("Scripting.FileSystemObject")
set fout = fso.CreateTextFile(server.mappath(""&filename&""))
fout.write request.form("body")
fout.close
set fout=nothing
set fso=nothing
end if
%>
这样index.html文件就生成了,连模板都用不着,只要将正常情况下使用的ASP文件读取到textarea里就可以了,目前尚未发现问题!当然前提是服务器要支持FSO
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/390618/viewspace-889705/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/390618/viewspace-889705/