當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