<%
'判断是否要生成新的HTML
ifApplication("cache_asptohtml_date")=""then
Application.Lock
Application("cache_asptohtml_date")=now()
Application.Unlock
CallaspTohtml
Response.Redirect("index.html")
endif
ifDateDiff("s",Application("cache_asptohtml_date"),Now)>100then'比较上次更新时间与当前时间相差多少秒
Application.Lock
Application("cache_asptohtml_date")=now()
Application.UnLock
CallaspTohtml
Response.Redirect("index.html")
Else
Response.Redirect("index.html")
Endif
'获取当前目录!
functiongetpath
ifRequest.ServerVariables("SERVER_PORT")<>"80"then
UserUrl="http://"&Request.ServerVariables("SERVER_NAME")&":"&Request.ServerVariables("SERVER_PORT")&Request.ServerVariables("URL")
else
UserUrl="http://"&Request.ServerVariables("SERVER_NAME")&Request.ServerVariables("URL")
endif
getpath=left(UserUrl,InstrRev(UserUrl,"/"))
endfunction
subaspTohtml
'----------------------------------------------------------
'使用XMLHTTP生成静态首页的代码
'Curl为你的首页地址,确保你的空间支持FSO
'-----------------------------------------------------------
dimread,Curl,content
Curl=getpath&"home.asp"
read=getHTTPPage(Curl)
ifread<>""then
content=read
SetFso=Server.CreateObject("Scripting.FileSystemObject")
Filen=Server.MapPath("index.html")
SetSite_Config=FSO.CreateTextFile(Filen,true,False)
Site_Config.Writecontent
Site_Config.Close
SetFso=Nothing
endif
Endsub
FunctiongetHTTPPage(url)
dimhttp
sethttp=Server.createobject("Microsoft.XMLHTTP")
Http.open"GET",url,false
Http.send()
ifHttp.readystate<>4then
exitfunction
endif
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
sethttp=nothing
iferr.number<>0thenerr.Clear
EndFunction
FunctionBytesToBstr(body,Cset)
dimobjstream
setobjstream=Server.CreateObject("adodb.stream")
objstream.Type=1
objstream.Mode=3
objstream.Open
objstream.Writebody
objstream.Position=0
objstream.Type=2
objstream.Charset=Cset
BytesToBstr=objstream.ReadText
objstream.Close
setobjstream=nothing
EndFunction
%>
ASP定时生成静态页(HTML)2
代码如下:
<%
setfs=server.createobject("scripting.filesystemobject")
file=server.mappath("time.txt")
settxt=fs.opentextfile(file,1,true)
ifnottxt.atendofstreamthen
times=txt.ReadLine
Else
response.write"<br/><!--有没有发现time.txt开始生成!-->"
HtmlPage="time.txt"'//生成的HTML文件名
Template=NOW()
SetFSO=Server.CreateObject("Scripting.FileSystemObject")
SetFileOut=FSO.CreateTextFile(Server.MapPath(HtmlPage))
FileOut.WriteLineTemplate
FileOut.Close
SetFSO=Nothing
endIf
Ifdatediff("s",times,NOW())>3600Then'//上次更新到现在的时间大于3600秒则更新
response.write"<br/><!--时间过了开始更新-->"
code="这里是需要生成的html代码"'//如何得到代码的方式有很多
'//用FSO生成HTML页面
HtmlPage="index.html"'//生成的HTML文件名
Template=code
SetFSO=Server.CreateObject("Scripting.FileSystemObject")
SetFileOut=FSO.CreateTextFile(Server.MapPath(HtmlPage))
FileOut.WriteLineTemplate
FileOut.Close
SetFSO=Nothing
'//用FSO生成time.txt文件
HtmlPage="time.txt"'//生成的HTML文件名
Template=NOW()
SetFSO=Server.CreateObject("Scripting.FileSystemObject")
SetFileOut=FSO.CreateTextFile(Server.MapPath(HtmlPage))
FileOut.WriteLineTemplate
FileOut.Close
SetFSO=Nothing
Else
response.write"<br/><!--已经过去"&datediff("s",times,NOW())&"秒!-->"
EndIf
%>
|