请教高手,ASP如何将首页转静态(急)
有谁懂得ASP动态程序,自动转为HTML 的程序代码!我不懂,社区的朋友帮帮忙! 问题点数:20、回复次数:2Top
1 楼cch345(漂零星)回复于 2006-07-02 09:55:50 得分 0
自动转的一般比较麻烦,要用到FSO,就是后台发布的相关产品的时候,只要牵涉到首页的那就要在发布后立即将首页删掉,然后重新生成一份.还要用到msxml组件,总体来讲比较复杂!Top
2 楼aspower_(敬个礼 握个手 大家都素好朋友!)回复于 2006-07-02 10:20:41 得分 0
最简单的办法
获取页面内容 可生成任意动态页面的静态页
<%
'常用函数
'1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
end function
'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
txtURL=server.MapPath("../index.asp")
sText = getHTTPPage(txtURL)
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
filename="../index.htm"
Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立
openFile.writeline(sText)
Set OpenFile=nothing
%>
<script>
alert("静态网页生成完毕");
history.back();
</script>
这样就在默认目录下生成和index.asp一样的index.htm了
然后修改默认页面为index.htm 以后就不会运行index.asp直接访问index.htmTop




