仓酷云

标题: ASP编程:Using the Counters Object (1) [打印本页]

作者: 灵魂腐蚀    时间: 2015-1-16 22:48
标题: ASP编程:Using the Counters Object (1)
无法实现跨操作系统的应用。当然这也是微软的理由之一,只有这样才能发挥ASP最佳的能力。可是我却认为正是Windows限制了ASP,ASP的概念本就是为一个能让系统运行于一个大的多样化环境而设计的;objectIntroduction:
Inyesterdaysarticle,RecordingPageHitswithMicrosoftsPageCounterObjectweexaminedusingMicrosoftsPageCounterobjecttotrackthenumberofhitsforanyparticularWebpage.Unfortunatelythiscomponentisonlybuiltforcountingpageviewhits.Ifwewantedtocountsomethingelse,sayeachtimeauserenteredaparticularsearchqueryintooursitessearchpage,wedbehardpressedwithusingthePageCounterobject.FortunatelyMicrosoftalsoprovidesdeveloperswithamoregenericcountingobject,theCountersobject.Thisobjectcanbeusedtotrackanindeterminentnumberofdeveloper-definedcounters.

BoththePageCounterandCounterscomponentsaremadeavailablewithMicrosoftsIISResourceKit.UnfortunatelythereisshoddydocumentationfortheIISResourceKit-itseemstobeisntalledonIIS5(Windows2000)bydefault,butolderversionsofIISmaynothaveitproperlyinstalled.Refertothepreviousarticle,RecordingPageHitswithMicrosoftsPageCounterObject,formoreinformationontheIISResourceKitandhowtoobtainitifyoudonthaveitinstalled.

AssumingyouhavetheIISResourceKitcomponentsproperlyinstalledyoushouldbeabletocreateaninstanceoftheCountersobjectusingthefollowingcode:

<%Setobj=Server.CreateObject("MSWC.Counters")%>


IfyougetaServer.CreateObjectFailed,Invalidclassstringerrorthenthecomponentsarenotproperlyinstalled.(IfthisisthecaseyoushouldtrychangingMSWC.CounterstoIISSample.Countersandcrossyourfingers.)Ifyoureceivenosucherrormessagethenthecomponentisproperlyinstalled.

UsingtheCountersObject:
TheCountersobjectallowsyoutocreateanynumberofpersistentcounters.WhenusingtheCountersobjectitissmartesttocreateasinlgeapplication-wideinstanceofthisobject.WecanmosteasilydothisbyaddingthefollowinglinetothetopofourGlobal.asafile:

<OBJECTRUNAT=ServerSCOPE=ApplicationID=objCounterPROGID="MSWC.Counters"></OBJECT>


TolearnmoreaboutGlobal.asabesuretoread:EverythingyouWantedtoKnowaboutGlobal.asabutwereafraidtoAskandGlobal.asaEventsaswellastheCreatingaGlobal.asaFilesectionofthesamplechapterofSamsTeachYourselfASP3.0in21Days!

OncethislineisaddedtoGlobal.asayoucanaccesstheCountersobjectfromanyASPpageinyourWebsitebytheobjectsIDthatwespecifiedintheOBJECTtag:objCounter.LikethePageCounterobjectdiscussedinyesterdaysarticle,theCountersobjectisafairlysimpleobjectconsistingofonlyfourmethods:


Get(CounterName)-RetrievesthecurrentvalueofthecounterspecifiedbythenameCounterName

Increment(CounterName)-IncrementsthecurrentvalueofthecounterspecifiedbythenameCounterName

Remove(CounterName)-RemovesthecounterspecifiedbythenameCounterNamefromthetextfilecounters.txt.Thistextfileiswherethecounterinformationispersisted.

Set(CounterName,Value)-SetsthevalueofthecounterspecifiedbythenameCounterNametothevaluespecifiedbyValue
So,oncewehaveaddedtheOBJECTtagabovetoourGlobal.asafilewecanstartworkingwiththeCountersobjectfromanyASPpageonourWebsite.WecouldusetheCountersobjectmuchlikeweusedthePageCounterobject.Forexample,ifwewantedtocreateacountertoseehowmanyfolksvisitedourhomepagewecouldusethefollowingcodeonourhomepage:

<%
Incrementthehomepagecounter
objCounter.Increment("HomePage")

Displayhowmanyhitswevehad
Response.Write"Therehavebeen"&objCounter.Get("HomePage")&"hits."
%>




ThecounternameHomePagedoesntrepresentanyspecialsortofname.Youcansimplycreateacounterbyspecifyingauniquename.Oncethecounteriscreatedyoucanincrementit,changeit,getitscurrentvalue,orremoveitfromanypageonyourWebsite.So,ifonanotherpageyouhadthesamecodeasaboveandtenvisitorshityourhomepageandthenfivevisitorshitthissecondpage,thevaluefortheHomePagecounterwillbe15-10hitsfromthehomepageand5hitsfromthesecondarypage.

InPart2wellexaminetheCountersobjectinmoredetail,lookingathowandwhereitsvaluesarepersisted.Wellalsolookatsomecodetodisplayallofthevaluesofthevariouscounterswemayhavecreated!
</p>asp可以轻松地实现对页面内容的动态控制,根据不同的浏览者,显示不同的页面内容。而浏览者一点觉察不出来,就像为他专门制作的页面一样。使用各种各样的组件,asp可以完成无比强大的功能。
作者: 若天明    时间: 2015-1-17 22:54
另外因为asp需要使用组件,所以了解一点组件的知识(ADODB也是组件)
作者: 柔情似水    时间: 2015-1-21 09:49
我想问如何掌握学习节奏(先学什么再学什么)最好详细点?
作者: 飘飘悠悠    时间: 2015-1-30 14:08
虽然ASP也有很多网络教程。但是这些都不系统。都是半路出家,只是从一个例子告诉你怎么用。不会深入讨论,更不会将没有出现在例子里的方法都一一列举出来。
作者: 再见西城    时间: 2015-2-6 13:11
以HTML语言整合(HTML负责界面上,ASP则负责功能上)形成一个B/S(浏览器/服务器)模式的网页程序。
作者: 山那边是海    时间: 2015-3-5 00:11
完全不知道到底自己学的是什么。最后,除了教程里面说的几个例子,还是什么都不会。
作者: admin    时间: 2015-3-11 21:52
Request:从字面上讲就是“请求”,因此这个是处理客户端提交的东东的,例如Resuest.Form,Request.QueryString,或者干脆Request("变量名")
作者: 只想知道    时间: 2015-3-19 14:45
弱类型造成潜在的出错可能:尽管弱数据类型的编程语言使用起来回方便一些,但相对于它所造成的出错几率是远远得不偿失的。
作者: 爱飞    时间: 2015-3-28 13:18
从事这个行业,那么你可以学ASP语言,简单快速上手,熟练dreamweav排版,写asp代码,熟练photoshop处理图片,打好基础就行了




欢迎光临 仓酷云 (http://www.ckuyun.com/) Powered by Discuz! X3.2