您正在使用 IPV4 [34.228.52.21] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
悟空收录网       [公益]保护绿色环境,构建和谐社会      

【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中      
[公益] 地球是我家,绿化靠大家      
2023年 圣诞节 023
2024年 腊八节 047
2024年 元 旦 030
2024年 春 节 070
 
您现在的位置:首页 >> ASP/ASP.net >> 内容
本类新增
本类热门文章
asp定时生成静态HTML的代码
内容摘要: %'判断是否要生成新的HTMLifApplication('cache_asptohtml_date')=''thenApplication.LockApplication('cache_asptohtml_date')=now()Application.UnlockCallaspTohtmlResponse.Redirect('index.html')en......
<%

'判断是否要生成新的HTML

ifApplication("cache_asptohtml_date")=""then

Application.Lock

Application("cache_asptohtml_date")=now()

Application.Unlock

CallaspTohtml

Response.Redirect("index.html")

endif

ifDateDiff("s",Application("cache_asptohtml_date"),Now)>100then'比较上次更新时间与当前时间相差多少秒

Application.Lock

Application("cache_asptohtml_date")=now()

Application.UnLock

CallaspTohtml

Response.Redirect("index.html")

Else

Response.Redirect("index.html")

Endif

'获取当前目录!

functiongetpath

ifRequest.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")

endif

getpath=left(UserUrl,InstrRev(UserUrl,"/"))

endfunction

subaspTohtml

'----------------------------------------------------------

'使用XMLHTTP生成静态首页的代码

'Curl为你的首页地址,确保你的空间支持FSO

'-----------------------------------------------------------

dimread,Curl,content

Curl=getpath&"home.asp"

read=getHTTPPage(Curl)

ifread<>""then

content=read

SetFso=Server.CreateObject("Scripting.FileSystemObject")

Filen=Server.MapPath("index.html")

SetSite_Config=FSO.CreateTextFile(Filen,true,False)

Site_Config.Writecontent

Site_Config.Close

SetFso=Nothing

endif

Endsub

FunctiongetHTTPPage(url)

dimhttp

sethttp=Server.createobject("Microsoft.XMLHTTP")

Http.open"GET",url,false

Http.send()

ifHttp.readystate<>4then

exitfunction

endif

getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")

sethttp=nothing

iferr.number<>0thenerr.Clear

EndFunction

FunctionBytesToBstr(body,Cset)

dimobjstream

setobjstream=Server.CreateObject("adodb.stream")

objstream.Type=1

objstream.Mode=3

objstream.Open

objstream.Writebody

objstream.Position=0

objstream.Type=2

objstream.Charset=Cset

BytesToBstr=objstream.ReadText

objstream.Close

setobjstream=nothing

EndFunction

%>

ASP定时生成静态页(HTML)2

代码如下:

<%

setfs=server.createobject("scripting.filesystemobject")

file=server.mappath("time.txt")

settxt=fs.opentextfile(file,1,true)

ifnottxt.atendofstreamthen

times=txt.ReadLine

Else

response.write"<br/><!--有没有发现time.txt开始生成!-->"

HtmlPage="time.txt"'//生成的HTML文件名

Template=NOW()

SetFSO=Server.CreateObject("Scripting.FileSystemObject")

SetFileOut=FSO.CreateTextFile(Server.MapPath(HtmlPage))

FileOut.WriteLineTemplate

FileOut.Close

SetFSO=Nothing

endIf

Ifdatediff("s",times,NOW())>3600Then'//上次更新到现在的时间大于3600秒则更新

response.write"<br/><!--时间过了开始更新-->"

code="这里是需要生成的html代码"'//如何得到代码的方式有很多

'//用FSO生成HTML页面

HtmlPage="index.html"'//生成的HTML文件名

Template=code

SetFSO=Server.CreateObject("Scripting.FileSystemObject")

SetFileOut=FSO.CreateTextFile(Server.MapPath(HtmlPage))

FileOut.WriteLineTemplate

FileOut.Close

SetFSO=Nothing

'//用FSO生成time.txt文件

HtmlPage="time.txt"'//生成的HTML文件名

Template=NOW()

SetFSO=Server.CreateObject("Scripting.FileSystemObject")

SetFileOut=FSO.CreateTextFile(Server.MapPath(HtmlPage))

FileOut.WriteLineTemplate

FileOut.Close

SetFSO=Nothing

Else

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

EndIf

%>

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:取得multipart/form-dat 下一篇:asp.net下文件上传和文件删除的代码
发布日期:2023/11/20
手机扫二维码直达本页
发布时间:16:09:36
点  击:21
录  入:星儿
相关文章
Baidu
YiJiaCMS 7.3.5 build231025(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,Cloudflare提供加速防护
运行时间载入中.....