ASP网页设计再贴一遍,使用global.asp准时实行ASP
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来写程序就可以说自己高档了 先学习用frontpage熟悉html编辑然后学习asp和vbscript建议买书进行系统学习 不是很难但是英文要有一点基础网上的教程很少有系统的详细的去买书吧,另不用专门学习vb关于vbscript脚本在asp教材都有介绍 尽管MS自己讲C#内核中更多的象VC,但实际上我还是认为它和Java更象一些吧。首先它是面向对象的编程语言,而不是一种脚本,所以它具有面向对象编程语言的一切特性,比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。 封装性使得代码逻辑清晰,易于管理,并且应用到ASP.Net上就可以使业务逻辑和Html页面分离,这样无论页面原型如何改变,业务逻辑代码都不必做任何改动;继承性和多态性使得代码的可重用性大大提高。 弱类型造成潜在的出错可能:尽管弱数据类型的编程语言使用起来回方便一些,但相对于它所造成的出错几率是远远得不偿失的。 不是很难但是英文要有一点基础网上的教程很少有系统的详细的去买书吧,另不用专门学习vb关于vbscript脚本在asp教材都有介绍 封装性使得代码逻辑清晰,易于管理,并且应用到ASP.Net上就可以使业务逻辑和Html页面分离,这样无论页面原型如何改变,业务逻辑代码都不必做任何改动;继承性和多态性使得代码的可重用性大大提高。 Server:这个表示的服务器,操作服务器的一些东西使用这个,如Server.Mappath转换服务器路径,Server.CreateObject实例化一个组件 你可以通过继承已有的对象最大限度保护你以前的投资。并且C#和C++、Java一样提供了完善的调试/纠错体系。
页:
[1]