|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
实现规模效益。与传统的用户拥有硬件软件所有权和使用权以及传统的应用服务商提供一对一的服务模式不同,ASP拥有应用系统所有权,用户拥有使用权,应用系统集中放在ASP的数据中心中,集中管理,分散使用,以一对多的租赁的形式为众多用户提供有品质保证的应用技术服务,实现规模效益。session
IfyouareusingASP3.0(theversionofASPthatcomeswithWindows2000/IIS5)thenyoucanusethefollowingsyntax:
Session.Contents.Remove"name"
whereNameisthenameoftheSessionvariableyouwishtoremove.RemovingSessionvariablesinthiswayhasitsadvantagesoverusingthefollowingmethod:
Session("Name")=Null
Namely,theabovemethod(settingaSessionvariabletoNull)onlyremovesthememoryassociatedwiththeSessionvariableitself...theSessionobjectstillmaintainsareferencetoit,though.EachSessionvariablesisstoredintheSessionobjectwithakey/itempair,similartotheScripting.Dictionaryobject.Therefore,usingtheNullmethodabove,youarenotremovingthekeyfromtheSessionContentscollectionthatcontainsthereferencetothevariable...
WiththeRemovemethodthatwelookedatfirst,youareremovingboththekeyanditemassociatedwithaSessionvariable.ThereisalsoaRemoveAllmethodthatcanbeusedtoscrapalloftheSessionvariablescompletely:
Session.Contents.RemoveAll
Again,theRemoveandRemoveAllmethodsarenewtoASP3.0.IfyouhaveASP2.0,youwillneedtousetheNullmethod
DeletingaSubsetofSessionVariables
WhenusingSessionstostorevariablesin,Iuseanamingconvention-forexample,forallCustomerrelatedinfoIprefixthesessionvariablewiththesubstringCustomer.(sofortheCustomerIDitwouldbeCustomer.ID,thecustomerusernamewouldbeCustomer.Name,etc.)Thisisveryusefulwhenviewingthesessionobjectsasyoucanseetherelatedobjectsstraightoff.
TheproblemIhadtheotherdaywasthatIwantedtoremoveonlythoseitemsfromtheSessionwhichwereprefixedSW..SofirstoffIusedthefollowingcode:
---------------------------------------
Session("SW.1")="Test1"
Session("SW.2")="Test2"
Session("Other")="Other"
ForEachSessionIteminSession.Contents
IfLeft(SessionItem,3)="SW."then
Session.Contents.Remove(SessionItem)
endif
Next
---------------------------------------
Thisseemsfine,butwhenitsrun,whathappensisthatSW.1isremoved,butSW.2isNOTremoved.Why?Imnotexactlysure,butIguessthattheindexisthenresetsothatSW.2isnowwhereSW.1was,andseeingaswehaveiteratedpastthatitemintheForEach...Nextstatement,theloopjustmovestoOther,missingoutSW.2altogether!Eek!
SotogetroundthisIwrotethefollowingfunction,whichwillproperlydeleteallSessionvariablesthatbeginwithaspecifiedsubstring:
---------------------------------------
functionSessionRemoveSelected(sItemPrefix)
/////////////////////////////////////////////////
RemoveSelectedItemsstartingwithsItemPrefix
fromtheSession.e.g.SS.willremoveSS.IDand
SS.NAMEbutnotCustomerIDReturnsTrueorFalse
dependingonwhetheranyitemswhereremoved.
---------------------------------------
sItemPrefix[string]:ItemPrefix
/////////////////////////////////////////////////
dimarySession()
dimlCount,lPrefixLength
dimSessionItem
dimblnResult
lCount=-1
lPrefixLength=len(sItemPrefix)
blnResult=false
temporarilystoreinarrayitemstoremove
ForEachSessionIteminSession.Contents
ifleft(SessionItem,lPrefixLength)=sItemPrefixthen
lCount=lCount+1
redimpreservearySession(lCount)
arySession(lCount)=SessionItem
endif
Next
removeitems
ifIsArray(arySession)andlCount>=0then
forlCount=LBound(arySession)toUBound(arySession)
Session.Contents.Remove(arySession(lCount))
next
blnResult=true
endif
SessionRemoveSelected=blnResult
endfunction
-------------------------------------------------
实现规模效益。与传统的用户拥有硬件软件所有权和使用权以及传统的应用服务商提供一对一的服务模式不同,ASP拥有应用系统所有权,用户拥有使用权,应用系统集中放在ASP的数据中心中,集中管理,分散使用,以一对多的租赁的形式为众多用户提供有品质保证的应用技术服务,实现规模效益。 |
|