ASP は定期的に静的 HTML コードを生成します。これは、サーバーの負荷を軽減するのに非常に役立ちます。
次のようにコードをコピーします。<%
'新しい 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 '最終更新時刻と現在の時刻の差の秒数を比較します
Application.Lock
Application(cache_asptohtml_date)=now()
Application.UnLock
Call aspTohtml
Response.Redirect(index.html)
Else
Response.Redirect(index.html)
End if
'現在のディレクトリを取得します
function getpath
if Request.ServerVariables(SERVER_PORT)<>80次に、
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
サブ aspTohtml
'------------------------------------------------- -- ----------
「XMLHTTP を使用して静的ホームページのコードを生成します」Curl は
ホームページのアドレスです。スペースが 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 関数
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 は定期的に静的ページ (HTML) を生成します 2.
次のコードをコピーします。
<%
set fs=server.createobject(scripting.filesystemobject)
file=server.mappath(time.txt)
セットtxt=fs.opentextfile(file,1,true)
txt.atendofstream でない場合は、
times=txt.ReadLine
それ以外の
場合は、response.write <br /><!--time.txt の生成が開始されていることがわかりましたか!-- >
HtmlPage = time .txt '//生成された HTML ファイル名
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 '//最後の更新からの時間が次より大きい3600 秒、
response.write を更新します<br /><!--時間が経過したら更新を開始します-->
code =生成する必要がある HTML コードは次のとおりです '//コードを取得するにはさまざまな方法があります
'//FSO を使用して HTML ページを生成します
HtmlPage =index.html '//生成される HTML ファイル名
Template = code
Set FSO = Server.CreateObject (Scripting.FileSystemObject)
Set FileOut = FSO.CreateTextFile(Server.MapPath (HtmlPage))
FileOut.WriteLine テンプレート
FileOut.Close
Set FSO = Nothing
'//FSO を使用して time.txt ファイルを生成します。
HtmlPage = time.txt '//生成された HTML ファイル名
Template = NOW()
Set FSO = Server.CreateObject (Scripting.FileSystemObject)
Set FileOut = FSO.CreateTextFile(Server.MapPath ( HtmlPage))
FileOut.WriteLine テンプレート
FileOut.Close
Set FSO = Nothing
Else
response.write <br /><!-- 経過しました&datediff(s,times,NOW())&秒!-->
End If
%>