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

当ASP会话结束时,会运行global.asa中的Session_OnEnd方法。可在此方法中删除因超时而终止会话的用户,并记录用户终止会话的原因。文中给出了通过更新Users表的TimedOut字段实现该功能的代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

五、会话终止

   当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


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124612/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124612/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值