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
%>


猜你喜欢
- 无参修饰 ,无参数时不需要调用def log1(func): func()@log1def test(): prin
- 本文已经收录于最新版的 《PyCharm中文指南》更多 PyCharm 使用技巧,可前往在线文档学习:《PyCharm 中文指南》2.0 在
- 对于opencv 它提供了许多已经练习好的模型可供使用,我们需要通过他们来进行人脸识别参考了网上许多资料 假设你已经配好了开发环境
- 简介Go 标准库提供 Cond 原语的目的是,为等待 / 通知场景下的并发问题提供支持。Cond 通常应用于等待某个条件的一组 gorout
- 不夸张地说,XML正在接管这个世界,正在成为今天一切Web服务和大多数SOA的基础。XML本身并非一种技术,而是程序设计语言,可支持开发者为
- 前言在日常的业务数据分析 ,可视化是非常重要的步骤。这里总结了matplotlib常用绘图技巧,希望可以帮助大家更加更加高效的、美观的显示图
- 如下所示:# coding=utf-8import pandas as pd# 读取csv文件 3列取名为 name,sex,births,
- 如下所示:<strong><span style="font-size:14px;">文本过滤&
- 前言之前学习过node.js接触过express框架,最近为了编写一个mock server正好用到了express。下面正好就跟大家介绍一
- 线程间通信方法 1. 通信方法线程间使用全局变量进行通信 2. 共享
- 前言大家都知道Python的优点是开发效率高,使用方便,C++则是运行效率高,这两者可以相辅相成,不管是在Python项目中嵌入C++代码,
- 在项目中遇到了个json数据需要解析,利用Python脚本尝试分享给大家如下:import osimport pandas as pdimp
- 大家可以在Github上clone全部源码。Github:https://github.com/williamzxl/Scrapy_Craw
- 随着短视频应用的普及,越来越多人开始了解并尝试制作自己的短视频作品。而在制作短视频时,背景音乐的选择和使用也是非常重要的一步。很多人喜欢选择
- 解决方法: 给 audio 组件绑定点击事件,手动触发播放暂停方法!代码片段:wxml文件<!-- 判断是语音通话,有通话记录,通话描
- pip install命令用于安装扩展库,由于安装扩展库需要从国外网站下载,速度较慢,可以使用-i选项设置临时使用国内的镜像网站。命令格式:
- 一、问题说明首先,运行下述代码,复现问题:# -*-coding:utf-8-*-import reimport requestsfrom
- 地理图表什么是地理图表?地理图表有什么作用?地理图表主要应用在那些领域?其实这些问题看看下面的实例图形就已不攻自破了,地理图表一看首先就是地
- 本文实例讲述了Python栈的实现方法。分享给大家供大家参考,具体如下:Python实现栈栈的数组实现:利用python列表方法代码如下:#
- 目录前言总结:1.代码块的缓存机制2.小数据池3.优缺点小整数对象池大整数对象池字符串驻留机制简单原理:前言本文除"总结"