在ASP应用中验证用户身份(5)
程序员文章站
2022-05-27 08:10:05
五、会话终止 当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
当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
上一篇: 到底是不是在一个季节里啊
下一篇: 在ASP应用中验证用户身份(1)