仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 605|回复: 9
打印 上一主题 下一主题

[学习教程] ASP网页设计再贴一遍,使用global.asp准时实行ASP

[复制链接]
冷月葬花魂 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 23:18:15 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
SQLServer是基于服务器端的中型的数据库,可以适合大容量数据的应用,在功能上管理上也要比Access要强得多。在处理海量数据的效率,后台开发的灵活性,可扩展性等方面强大。准时|实行Usingtheglobal.asatoscheduleASPcodeexecution.
Haveyoueverhadsomeaspcodethatneededtoexecuteeveryonceinawhilebut,youjustdidntknowhowtodoit.

Thereisasolutionthatdoesntinvolverunninganyschedulingorscriptingsoftwareontheserverandisactuallyveryeasytogetworking.

Yousee...thereisthingcalledthe"global.asa".MostASPnewbiesprobablywonderwhattheheckitevenis.TheGlobal.asafileiseventdriven.Itcancontainfoureventprocedures:Application_OnStart,Application_OnEnd,Session_OnStart,andSession_OnEnd.

Theglobal.asaisbasicallyloadedintomemorythefirsttimeanyuserviewsapageonyourWebapplication.Thereareeventprocedurestubsthatcancontainscriptyouwanttobeexecutedwhentheapplicationstartsorends,orwhenthesessionstartsorends.

Withsometrickycodingyoucanusethisfiletoschedulecodetoexecute.Atleastaroundthetimeyouneeditto,thiswontbeabletomakeitexecuteatexactlyacertaintime.

Hereisthe1stexample.Itsimplykeepstrackofhowmanyvisitorshavebeentoyoursiteandafter100itresetsthecountbackto0andexecuteswhatevercodeyouneedtorun.Obviouslyyoullneedtoadjustthe"100"towhatevermakessensefortheamountofvisitorsyoursitereceives.

Contentsoftheglobal.asaarebelow.

<SCRIPTLANGUAGE=VBScriptRUNAT=Server>

SubApplication_OnStart
Application("SessionCount")=0
EndSub

SubSession_OnStart

Application.Lock
Application("SessionCount")=Application("SessionCount")+1
Application.Unlock

IfApplication("SessionCount")>100Then

Application.Lock
Application("SessionCount")=0
Application.Unlock

Hereyouwouldputanycodeyouneedtorun
donotsurroundthecodewith<%%>tags
Forexampleyoumightrunadatabasequerythatchecksforexpiredaccounts

Endif

EndSub

</SCRIPT>

Nowletssayyouwantsomethingtoexecute4timesaday.Youcanstorethedate&timeinatextfileandcheckitperiodically.Whenthedateandtimegettobemorethan6hoursoldthecodewillwritethenewdate&timetothetextfileandthenexecutethecodeyouwanttorun.Youcouldchangethe"6"towhateveryouwantandthereforeexecutethecodemoreorlessoften,

Thisisaprettyslicksolutionthoughitrequirescorrectpermissionstothetextfileforreading&writing.Ifnotyoullgetanerror.

Inthisexamplewearecheckingthetextfileevery15visitors.Youcanadjustthisamountorremovethe"check"completelysothatitchecksthefileeverytime,butwhycheckthefileeverytimewhenyouhaveaverybusysite?Thatwouldjustbeawasteofserverresources,butitisuptoyouhowfaryouwanttotakethis.

Inthisexampleyouneedtostartthetextfileoffwithavaliddate&timeorelseyouwillgetanerrorbecausethescriptwillreadinanemptyvaluethe1sttime.

EXAMPLE:put6/30/996:58:45PMinthe1stlineofthetextfile.

Youcouldaddcodetocheckforthatandhandletheerror,butIdidntreallycareatthetimesoIdidntdothat.Aslongasthereisadatetherewhenitstartsitwillkeepworking.

Contentsoftheglobal.asaarebelow.

<SCRIPTLANGUAGE=VBScriptRUNAT=Server>

SubApplication_OnStart
Application("SessionCount")=0
EndSub

SubSession_OnStart

Application.Lock
Application("SessionCount")=Application("SessionCount")+1
Application.Unlock

IfApplication("SessionCount")>15Then

Application.Lock
Application("SessionCount")=0
Application.Unlock

SetObjMyFile=CreateObject("Scripting.FileSystemObject")
SetOpenMyFile=ObjMyFile.OpenTextFile(Server.MapPath("last-update.txt"))
MyFileValue=OpenMyFile.ReadLine
OpenMyFile.Close

IfDateDiff("h",MyFileValue,NOW)>6Then

Hereyouwouldputanycodeyouneedtorun
donotsurroundthecodewith<%%>tags
Forexampleyoumightrunadatabasequerythatch</p>国内有些大的CRM厂商的ASP就写得不错.无论是概念还是它里面用JAVASCRIPT的能力.并不是说现在的程序员用了ASP.NET来写程序就可以说自己高档了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-31 16:41

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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