asp定时生成静态HTML的代码
发布时间:2010-07-02 12:29:00
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
%>
猜你喜欢
- 我们可以利用err对象来判断。当程序没有出现错误就说明已经执行了sql操作: sql="insert into
- 这个分页使用的是0游标,也就是Rs.Open Sql,Conn,0,1。但是感觉也快不了多少,10万条数据的分页时间300多豪秒之间。风格A
- 比较简单的一个页面,类似csdn论坛在ns下的左边列表 描述: 1. 数据名:tree.mdb 表名:tree 表结构:id(自编)&nbs
- 成天都要与样式打交道的朋友,相信对CSS选择符(CSS Selectors)都不会陌生。不过对于刚接触或者还不是很熟悉css的朋友来说,能够
- 当前记录集不支持更新。这可能是提供程序的限制,也可能是选定锁定类型的限制 问题的解决方法如下:第一:ACC
- 在内容为主的网站中,搜索框往往是最常用的设计元素之一。从可用性的角度来看,搜索功能是用户有了明确的内容想看的时候最后使用的功能。如果一个网站
- 定义: 何为触发器?在SQL Server里面也就是对某一个表的一定的操作,触发某种条件,从而执行的一段程序。触发器是一个特殊的存储过程。
- JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它采用完全独立于语言的文本格式,可替换XML成
- 表示文字链接最清楚的方式是“蓝色文字+下划线”,这是在浏览器发展过程中形成的。这个问题大家都说过很多次了,我也曾经说过。然而,这样的规范却总
- 左右布局,图片的宽度不固定。正好前几天测试闭合浮动元素时发现了overflow的特殊现象,倒是正好可以用在这里。测试通过:ie6/7&nbs
- [root@vm1 ~]# rpm -ivh groundwork-foundation-pro-1.6.1-67.noarch.rpm P
- 作者:Roland Smart原文链接:http://www.adaptivepath.com/ideas/newsletter/archi
- 由于XML本身的诸多优点,XML技术已被广泛的使用,目前的好多软件技术同XML紧密相关,比如微软的.net 平台对xml提供了强大的支持,提
- 前段时间和哥们胡侃的时候还说腾讯抄的有水平,不过这次我溴了,腾讯房产被新浪乐居给幽默了一把。乐居:http://bj.house.sina.
- 对于个人用户来说,除了病毒和木马,网页中的隐形代码也开始严重地威胁着我们的安全,但大多数人却缺乏自我保护意识,对隐形代码的危害认识不够,甚至
- 内容摘要:网页设计师制作网页最常用的设计软件应该就算adobe的产品Photoshop了,当然Photoshop不仅可以设计网页,不过作为网
- 划动门菜单技术:运行代码框<style>body {font-size:12px;font-family:宋体}ul.TabBa
- 6、遮罩滤镜作用:该滤镜可以为对象建立一个覆盖于表面的膜,其效果就象戴着有色眼镜看物体一样。语法: {filter:mask(color=c
- 1.基本结构 create OR REPLACE PROCEDURE存储过程名字 ( 参数1 IN NUMBER, 参数2 IN NUMBE
- <!--#include file="strcheck.asp"--> <% '笔者在写程序的