在ASP应用中验证用户身份(5)
2000-08-29 10:54:06 来源:WEB开发网核心提示:五、会话终止 当asp会话结束时会运行global.asa中的session_OnEnd方法,可以在这里删除保存在application("Users")数组中由于超时而被终止会话的用户,在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
当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.net页面弄成伪静态页面
- ››Asp.net 中将汉字转换成拼音的方法
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
更多精彩
赞助商链接