源码网,源码论坛,源码之家,商业源码,游戏源码下载,discuz插件,棋牌源码下载,精品源码论坛

 找回密码
 立即注册
楼主: ttx9n

[ASP编程] asp定时生成静态HTML的代码

[复制链接]

7万

主题

861

回帖

32万

积分

论坛元老

Rank: 8Rank: 8

积分
329525
发表于 2010-6-20 23:45:29 | 显示全部楼层 |阅读模式
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" 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
%>

回复

使用道具 举报

3

主题

2万

回帖

163

积分

注册会员

Rank: 2

积分
163
发表于 2022-9-2 20:29:43 | 显示全部楼层
怕怕怕怕怕怕怕怕怕怕怕怕怕怕
TS人妖演出表演服务q3268336102电话13168842816
回复 支持 反对

使用道具 举报

2

主题

2万

回帖

146

积分

注册会员

Rank: 2

积分
146
发表于 2022-10-9 15:07:29 | 显示全部楼层
感谢楼主分享
回复 支持 反对

使用道具 举报

匿名  发表于 2022-10-9 16:37:13

online casino

online casinos
<a href="https://casinowingames.com/">casinos</a>
gambling
<a href="https://casinowellplay.com/">slots</a>
slots
<a href="https://casinogambiba.com/">casino real money</a>
gambling
<a href="https://casinoongames.com/">casino games</a>
回复 支持 反对

使用道具

匿名  发表于 2022-10-9 16:37:43

casinos online


casino game
<a href="https://casinowingames.com/">casino game</a>
casino online
<a href="https://casinowellplay.com/">online casino</a>
online casino
<a href="https://casinogambiba.com/">casino online</a>
online casinos
<a href="https://casinoongames.com/">casino</a>
回复 支持 反对

使用道具

匿名  发表于 2022-10-9 16:38:15

casino online

casinos online
<a href="https://casinowingames.com/">casinos</a>
casino game
<a href="https://casinowellplay.com/">casinos</a>
slots
<a href="https://casinogambiba.com/">casinos</a>
casinos
<a href="https://casinoongames.com/">casinos</a>
回复 支持 反对

使用道具

匿名  发表于 2022-10-9 16:38:58

casino real money

СБъUi79 ·±нУЪ 2022-9-2 20:29
ЕВЕВЕВЕВЕВЕВЕВЕВЕВЕВЕВЕВЕВЕВ

casino games
<a href="https://casinowingames.com/">casino online</a>
casinos
<a href="https://casinowellplay.com/">casinos online</a>
online casino
<a href="https://casinogambiba.com/">slots</a>
casino online
<a href="https://casinoongames.com/">online casinos</a>
回复 支持 反对

使用道具

匿名  发表于 2022-10-9 16:39:39

gambling

gambling
<a href="https://casinowingames.com/">casinos online</a>
casinos online
<a href="https://casinowellplay.com/">online casinos</a>
casinos
<a href="https://casinogambiba.com/">casino game</a>
slots
<a href="https://casinoongames.com/">casinos</a>
回复 支持 反对

使用道具

匿名  发表于 2022-10-9 16:40:12

casino real money

УОН 37.139.53.x ·±нУЪ 2022-10-9 16:38
casino games
casino online
casinos

casino online
<a href="https://casinowingames.com/">casinos</a>
slots
<a href="https://casinowellplay.com/">casinos</a>
online casinos
<a href="https://casinogambiba.com/">online casinos</a>
online casinos
<a href="https://casinoongames.com/">casino games</a>
回复 支持 反对

使用道具

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2022-10-25 05:16:47 | 显示全部楼层
而快乐你们快乐马年快乐
回复 支持 反对

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

手机版|小黑屋|网站地图|源码论坛 ( 海外版 )

GMT+8, 2025-2-5 14:53 , Processed in 0.064121 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表