法律法規
asp定時生成靜態HTML的代碼
信息來源:長沙做網站  /  發布時間:2010-6-15  /  瀏覽數量:
復制代碼 代碼如下:
<% 
’判斷是否要生成新的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" 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 
’---------------------------------------------------------- 
’使用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 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定時生成靜態頁(HTML)2 
復制代碼 代碼如下:
<% 
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 開始生成!-->" 
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 Template 
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 Template 
FileOut.Close 
Set FSO = Nothing 

Else 

response.write "<br /><!-- 已經過去"&datediff("s",times,NOW())&"秒!-->" 

End If 
%> 

詳細出處參考:http://www.jb51/article/23955.htm


上一條: 做網站設計師的福音:國內20個設計素材好網站
下一條: 服務器添加隱藏賬號和檢查刪除隱藏賬號的方法
相關熱門資訊  News
一二三客戶案例

  123 NETWORK

合作共贏,助您打開網絡營銷財富之間!

www.www69avpz.com

合作對接電話:0731-88571521

聯系方式

地址:湖南省長沙市天心區韶山南路248號南園503室

電話:13637482004    0731-88571521

網址:http://www.www69avpz.com/

郵箱:123@123007.com

在線QQ咨詢

需求咨詢

價格咨詢

微信咨詢

掃一掃進移動端

版權所有 © 長沙一二三網絡技術有限公司    統一社會信用代碼:91430103MACCH7984M    網站ICP備案號:湘ICP備2023006748號     湘公網安備 43010302001803號        
主站蜘蛛池模板: 国产女人18毛片水真多1| 中国国产成人精品久久| 两个男gay的做污污的过程| 男人j放进女人p全黄| 欧洲精品码一区二区三区免费看| 国产精品自产拍在线观看| 亚洲精品中文字幕无码蜜桃| 99久久无码一区人妻| 波多野结衣电影免费在线观看 | 亚洲日韩图片专区第1页| 78成人精品电影在线播放| 欧美日韩亚洲成色二本道三区 | 没带罩子的英语老师| 国产精品欧美在线不卡| 亚洲av无码一区二区三区电影| 久久五月天综合网| 日韩三级中文字幕| 国产亚洲真人做受在线观看| 久久久综合九色合综国产精品| 蜜芽亚洲欧美一区二区电影| 拍拍拍无挡视频免费观看1000| 四虎永久免费地址在线观看| 一本加勒比HEZYO无码人妻| 男人一边吃奶一边做边爱| 国产成人精品一区二区三在线观看| 亚洲欧洲日产国码在线观看 | 榴莲视频app色版| 国产三级在线播放线| 一本大道香蕉最新在线视频| 校园激情综合网| 伊人久久大香线蕉综合热线| 97久久精品亚洲中文字幕无码| 欧美中文在线视频| 国产乱子伦在线观看| 一个人看的www免费高清中文字幕 一个人看的www免费高清中文字幕 | 久久久久亚洲AV无码网站| 精品视频一区二区三区| 天天爱天天操天天干| 亚洲国产成人综合| 青青草99热这里都是精品| 婷婷开心深爱五月天播播|