首页 | 免费域名 | 个人服务器 | 一流信息监控拦截系统 | 虚拟主机知识库 | ASP 空间 | ASP技术大全 | 下载中心 | 客户服务中心
  7i24 > ASP技术大全 > 技巧与经验 >
    7i24 .Com  
  在ASP应用中验证用户身份(5)

7i24.Com不停为您服务


在ASP应用中验证用户身份(5)

作者:仙人掌工作室


五、会话终止

   当ASP会话结束时会运行global.asa中的Session_OnEnd方法,可以在这里删除保存在Application("Users")数组中由于超时而被终止会话的用户。记录用户是由于什么原因(超时还是显式退出)终止会话往往很有用处,下面的代码通过更新Users表的TimedOut字段实现该功能:
sub Session_OnEnd
dim AppUsers
dim aUser
dim I
dim j
dim conn
dim supportsCookies
dim foundUser
on error resume next
supportsCookies=Session("SupportsCookies")
Application.Lock
AppUsers = Application("Users")
foundUser = false
for I = 0 to ubound(AppUsers)
set aUser = AppUsers(I)
if supportsCookies then
if aUser("SessionID") = Session.SessionID then
foundUser = true
end if
elseif dateAdd("n", Session.timeout, aUser("LastActivity")) < now()
then
foundUser = true
end if
if foundUser then
set conn = server.createObject("ADODB.Connection")
conn.ConnectionString=Session("ConnectionString")
conn.ConnectionTimeout=Session("ConnectionTimeout")
conn.mode=Session("Mode")
conn.open
conn.execute "UPDATE Users SET TimedOut=1 WHERE Users.Signon='" &
aUser("Signon") & "'"
conn.close
set conn=nothing
set aUser=nothing
set AppUsers(I) = nothing
for j = I to ubound(AppUsers) - 1
set AppUsers(j) = AppUsers(j + 1)
next
if ubound(AppUsers) > 0 then
redim preserve AppUsers(ubound(AppUsers) - 1)
else
AppUsers = Array()
end if
exit for
end if
next
Application("Users") = AppUsers
Application.UnLock
end sub


  2002年1月14日  阅读 1615 次  发送此页给朋友  来源:    版权争议  删除

相关文章:   近期热点:

上一篇: 在ASP应用中验证用户身份(4)
下一篇: 一个可以管理来访页的程序例子,可以删除来访页并修改。
返回上一层...
搜索:

(C)2004-2022 7i24.Com 保留所有权利