欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-01-23 22:49:42
五、会话终止    当asp会话结束时会运行global.asa中的session_onend方法,可以在这里删除保存在application("users")数组中由于超时而被终...
五、会话终止

   当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