许多人首页调用数据库内容较多,导致首页打开速度很慢,明翔特地放上asp首页生成静态化htm文件的方法的源码,希望对大家有所帮助:
<%
Response.Expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.CacheControl = "no-cache"
Response.Buffer = True
Response.Clear
Server.ScriptTimeOut=999999999
on error resume next
'***************************************************************
'* 定义 从模板从读取首页 函数
'* 说明:模板文件名为:index.asp
'***************************************************************
Function GetPage(url)
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
GetPage = BytesToBstr(.ResponseBody)
End With
Set Retrieval = Nothing
End Function
Function BytesToBstr(body)
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 = "GB2312"
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
'***************************************************************
'* 生页首页,文件名为:index.htm
'***************************************************************
dim Tstr
Tstr = GetPage("http://121.234.118.58:8081/index.asp")
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(Server.MapPath(".")&"/index.htm")
fout.Write Tstr
fout.close
Response.write"<script>alert(""生成首页成功!\n\n文件名为:index.htm"");</script>"
Response.Redirect "http://www.seopets.com/"
Response.end
%>
这上面便是生成首页静态化文件的源码了,我另一个网站也做的是无锡网站建设,测试了没有什么问题,欢迎大家和我交流!