|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
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来写程序就可以说自己高档了 |
|