CopyCode The Code is as follows: <%
'Determine whether to generate a 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' compares the seconds between the last update time and the current time
Application. 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, limit Rev (userurl ,"/"))
End Function
sub asptohtml
'------------------------------------------------------
' Use XMLHTTP to generate static homepage Code
'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 regular generation of Static Page (HTML) 2Copy codeThe Code is 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/> <! -- Time.txt is 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' // if the time from the last update to the present is greater than 3600 seconds, the update
Response. Write "<br/> <! -- Start updating after time -->"
Code = "here is the HTML code to be generated" '// There are many ways to get the code
'// Use FSO to generate an HTML page
Htmlpage = "index.html" '// 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 fsoto generate the 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
%>