ASP สร้างโค้ด HTML แบบคงที่เป็นประจำ ซึ่งมีประโยชน์มากในการบรรเทาความกดดันของเซิร์ฟเวอร์ เพื่อนๆ ที่ต้องการความช่วยเหลือสามารถอ้างอิงถึงโค้ดนี้ได้
คัดลอกโค้ดดังนี้:<%
'พิจารณาว่าจะสร้าง HTML ใหม่
หรือไม่ถ้า Application(cache_asptohtml_date)= แล้ว
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 จากนั้น 'เปรียบเทียบจำนวนวินาทีที่แตกต่างกันระหว่างเวลาอัปเดตครั้งล่าสุดและเวลาปัจจุบัน
Application.Lock
Application(cache_asptohtml_date)=now()
Application.UnLock
Call aspTohtml
Response.Redirect(index.html)
Else
Response.Redirect(index.html)
สิ้นสุดถ้า
'รับไดเรกทอรีปัจจุบัน!
ฟังก์ชั่น getpath
ถ้า 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)
สิ้นสุดถ้า
getpath=left(UserUrl,InstrRev(UserUrl,/))
ฟังก์ชันสิ้นสุด
aspTohtml ย่อย
'--------------------------------------------------- -----------
'ใช้ XMLHTTP เพื่อสร้างโค้ดสำหรับหน้าแรกแบบคงที่'Curl
คือที่อยู่หน้าแรกของคุณ ตรวจสอบให้แน่ใจว่าพื้นที่ของคุณรองรับ FSO
'-------------------------- --------------------------------
dim read,Curl,content
Curl=getpath&home.asp
read=getHTTPPage(Curl)
ถ้า อ่าน <> แล้ว
เนื้อหา = อ่าน
ชุด Fso = Server.CreateObject (Scripting.FileSystemObject)
Filen = Server.MapPath (index.html)
ตั้ง Site_Config=FSO.CreateTextFile(Filen,true, False)
เนื้อหา Site_Config.Write
Site_Config.Close
Set Fso = ไม่มีอะไร
สิ้นสุดถ้า
End sub
Function getHTTPPage(url)
dim http
set http=Server.createobject(Microsoft.XMLHTTP)
Http.open GET, url,false
Http.send()
ถ้า Http.readystate<>4 จากนั้น
ออกจากฟังก์ชัน
สิ้นสุดถ้า
getHTTPPage=bytesToBSTR(Http.responseBody,GB2312)
ตั้งค่า http=nothing
if err.number<>0 แล้ว err.Clear
End Function
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject(adodb.stream)
objstream.Type = 1
objstream.Mode = 3
objstream.
เปิด objstream.เขียนเนื้อหา
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = none
End Function
%>
ASP สร้างสแตติกเพจ (HTML) เป็นประจำ 2.
คัดลอกโค้ดดังนี้:
<%
set fs= server.createobject(scripting.filesystemobject)
ไฟล์=server.mappath(time.txt)
ตั้งค่า txt=fs.opentextfile(file,1,true)
ถ้าไม่ใช่ txt.atendofstream แล้ว
times=txt.ReadLine
Else
response.write <br /><!--คุณพบว่า time.txt เริ่มถูกสร้างขึ้นแล้ว!-- >
HtmlPage = เวลา .txt '//ชื่อไฟล์ HTML ที่สร้าง
เทมเพลต = 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 The '//เวลาตั้งแต่การอัปเดตครั้งล่าสุดมีค่ามากกว่า 3600 วินาที อัปเดต
การตอบกลับเขียน <br /><!--เริ่มอัปเดตหลังจากเวลาผ่านไป-->
รหัส = นี่คือโค้ด html ที่ต้องสร้าง '//มีหลายวิธีในการรับโค้ด
'//ใช้ FSO เพื่อสร้างหน้า HTML
HtmlPage = index.html '//ชื่อไฟล์ HTML ที่สร้างขึ้น
Template = โค้ด
Set FSO = Server.CreateObject (การเขียนสคริปต์ FileSystemObject)
ตั้งค่า FileOut = FSO.CreateTextFile (Server.MapPath (HtmlPage))
FileOut.WriteLine เทมเพลต
FileOut.Close
ตั้งค่า FSO = ไม่มีเลย
'//ใช้ FSO เพื่อสร้างไฟล์ time.txt
HtmlPage = time.txt '//ชื่อไฟล์ HTML ที่สร้าง
เทมเพลต = NOW()
Set FSO = Server.CreateObject (Scripting.FileSystemObject)
Set FileOut = FSO.CreateTextFile(Server.MapPath ( HtmlPage))
FileOut.WriteLine เทมเพลต
FileOut.Close
ตั้งค่า FSO = ไม่มีอะไร
อื่น
response.write <br /><!-- มันผ่านไปแล้ว&datediff(s,times,NOW())&seconds!-->
End If
%>