网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.较长text型数据无法在Asp页面中取.
.如何编写通用的ASP防SQL注入攻击.
.ASP实现多语言支持.
.验证email地址是否合法完整实例.
.对ASP脚本源代码进行加密.
.关于ASP中堆栈溢出错误的解决.
.检查sql字符串中是否有单引号,有.
.ASP实用技巧28则.
.组合查询之核心:拼接字符串.
.无组件生成BMP验证码.
.ASP,PHP与.NET伪造HTTP-REFERER方.
.如何使用ASP产生象安装向导的主页.
.表单递交内容检测脚本-这里只接受.
.使用ASP常见问题解答.
.ASP关于动态数据显示页面得锚点.
.ASP与ASP.NET在COOKIE方面的区别.
.ADO如何新增修改刪除数据库的资料.
.ASP中轻松实现变量名-值变换.
.如何使用ASP在自己的网站建立投票.
.ISAPI Rewrite的安装与使用.

关于释放session的两篇文章(二)

发表日期:2001-4-5


Deleting a Subset of Session Variables

When using Sessions to store variables in, I use a naming convention - for example, for all Customer related info I prefix the session variable with the substring Customer. (so for the CustomerID it would be Customer.ID, the customer username would be Customer.Name, etc.) This is very useful when viewing the session objects as you can see the related objects straight off.

The problem I had the other day was that I wanted to remove only those items from the Session which were prefixed SW.. So first off I used the following code:

'---------------------------------------
Session("SW.1")="Test 1"
Session("SW.2")="Test 2"
Session("Other")="Other"

For Each SessionItem in Session.Contents
  If Left(SessionItem,3) = "SW." then
    Session.Contents.Remove(SessionItem)
  end if
Next
'---------------------------------------

This seems fine, but when it's run, what happens is that SW.1 is removed, but SW.2 is NOT removed. Why? I'm not exactly sure, but I guess that the index is then reset so that SW.2 is now where SW.1 was, and seeing as we have iterated past that item in the For Each...Next statement, the loop just moves to Other, missing out SW.2 altogether! Eek!

So to get round this I wrote the following function, which will properly delete all Session variables that begin with a specified substring:

'---------------------------------------
function SessionRemoveSelected(sItemPrefix)
'/////////////////////////////////////////////////
' Remove Selected Items starting with sItemPrefix
' from the Session. e.g. SS. will remove SS.ID and
' SS.NAME but not CustomerID Returns True or False
' depending on whether any items where removed.
'---------------------------------------
' sItemPrefix [string] : Item Prefix
'/////////////////////////////////////////////////
  dim arySession()
  dim lCount, lPrefixLength
  dim SessionItem
  dim blnResult
    
  lCount = -1
  lPrefixLength = len(sItemPrefix)
  blnResult = false
    
  ' temporarily store in array items to remove
  For Each SessionItem in Session.Contents
    if left(SessionItem,lPrefixLength) = sItemPrefix then
      lCount = lCount + 1
      redim preserve arySession(lCount)
      arySession(lCount) = SessionItem
    end if
  Next

  ' remove items
  if IsArray(arySession)and lCount >= 0 then
    for lCount = LBound(arySession) to UBound(arySession)
      Session.Contents.Remove(arySession(lCount))
    next
    blnResult=true
  end if

  SessionRemoveSelected = blnResult
end function
'-------------------------------------------------

上一篇:关于释放session的两篇文章(一) 人气:12554
下一篇:论坛树状记录表的堆栈展开 人气:10358
浏览全部的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐