ASP regularly generates static HTML code, which is very helpful in alleviating server pressure. Friends in need can refer to it.
Copy the code as follows:<%
'Determine whether to generate new HTML
if Application(cache_asptohtml_date)= then
Application.Lock
Application(cache_asptohtml_date)=now()
Application.Unlock
Call aspTohtml
Response.Redirect(index.html)
end if
if DateDiff (s, Application(cache_asptohtml_date),Now)> 100 then 'Compare the number of seconds difference between the last update time and the current
timeApplication.Lock
Application(cache_asptohtml_date)=now()
Application.UnLock
Call aspTohtml
Response.Redirect(index.html)
Else
Response.Redirect(index.html)
End if
'Get the current directory!
function getpath
if Request.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)
end if
getpath=left(UserUrl,InstrRev(UserUrl,/))
end function
sub aspTohtml
'------------------------------------------------- ----------
'Use XMLHTTP to generate the code for static homepage'Curl
is your homepage address, make sure your space supports FSO
'-------------------------- --------------------------------
dim read,Curl,content
Curl=getpath&home.asp
read=getHTTPPage(Curl)
if read<> then
content=read
Set Fso = Server.CreateObject(Scripting.FileSystemObject)
Filen=Server.MapPath(index.html)
Set Site_Config=FSO.CreateTextFile(Filen,true, False)
Site_Config.Write content
Site_Config.Close
Set Fso = Nothing
end if
End sub
Function getHTTPPage(url)
dim http
set http=Server.createobject(Microsoft.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
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
%>
ASP regularly generates static pages (HTML) 2.
Copy the code as follows:
<%
set fs= server.createobject(scripting.filesystemobject)
file=server.mappath(time.txt)
set txt=fs.opentextfile(file,1,true)
if not txt.atendofstream then
times=txt.ReadLine
Else
response.write <br /><!--Have you found that time.txt has started to be generated!-->
HtmlPage = time .txt '//Generated HTML file name
Template = NOW()
Set FSO = Server.CreateObject (Scripting.FileSystemObject)
Set FileOut = FSO.CreateTextFile(Server.MapPath (HtmlPage))
FileOut.WriteLine Template
FileOut.Close
Set FSO = Nothing
end If
If datediff(s,times,NOW()) > 3600 Then '//The time since the last update is greater than 3600 Seconds, update
response.write <br /><!--Start updating after time passes-->
code = Here is the html code that needs to be generated '//There are many ways to get the code
'//Use FSO to generate the HTML page
HtmlPage = index.html '//The generated HTML file name
Template = code
Set FSO = Server.CreateObject (Scripting. FileSystemObject)
Set FileOut = FSO.CreateTextFile(Server.MapPath (HtmlPage))
FileOut.WriteLine Template
FileOut.Close
Set FSO = Nothing
'//Use FSO to generate time.txt file
HtmlPage = time.txt '//Generated HTML file name
Template = NOW()
Set FSO = Server.CreateObject (Scripting.FileSystemObject)
Set FileOut = FSO.CreateTextFile(Server.MapPath ( HtmlPage))
FileOut.WriteLine Template
FileOut.Close
Set FSO = Nothing
Else
response.write <br /><!-- It has passed&datediff(s,times,NOW())&seconds!-->
End If
%>