• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

控制用户登陆到网站和显示在线用户列表

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 20次 | 进入软件测试论坛讨论

领测软件测试网
下面是global.asa的内容:

Sub Application_OnStart
‘’ Delete all saved session information, in case of a crash
set objADO = Server.CreateObject("ADODB.Connection")
sDatabasePath = Server.MapPath("/databases")
sConnection
= "filedsn="&sDatabasePath&"\readwrite.dsn;DBQ="&sDatabasePath&"\sessi
ons.mdb;"
objADO.Open(sConnection)

sUpdateCmd = "delete * from session;"
objADO.Execute(sUpdateCmd)
‘’ Close the database down again
objADO.close
set objADO=Nothing

‘’ Now store the DSN connection string away, so we don‘’t have to look
it up again
Application("sessionDSN") = sConnection

End Sub

Sub Session_OnStart

‘’ Write the session information away into the session database
set session_objADO = Server.CreateObject("ADODB.Connection")
session_objADO.Open(Application("sessionDSN"))
session_sUpdateCmd = "insert into session values
("&Session.SessionID&","
session_sUpdateCmd = session_sUpdateCmd & "‘’"&Request.ServerVariables
("REMOTE_ADDR")& "‘’,"
session_sUpdateCmd = session_sUpdateCmd & "‘’"&Request.ServerVariables
("HTTP_USER_AGENT")&"‘’);"
session_objADO.Execute(session_sUpdateCmd)
‘’ Close the database down again
session_objADO.close
set session_objADO=Nothing

End Sub

Sub Session_OnEnd

‘’ Delete the session information from the session database
set session_objADO = Server.CreateObject("ADODB.Connection")
session_sConnection = Application("sessionDSN")
session_objADO.Open(session_sConnection)
session_sUpdateCmd = "delete * from session where
SessionID="&Session.SessionID&";"
session_objADO.Execute(session_sUpdateCmd)
‘’ Close the database down again
session_objADO.close
set session_objADO=Nothing

End Sub

下面是实现功能的一个例子:

<% OPTION EXPLICIT

‘’ currentusers.asp V1.0
‘’ Copyright 1998/99 Bann Consultants [email protected]
‘’ Created 03/11/98 Modified 03/11/98
‘’ On-line documentation at http://www.bann.co.uk/asp/
‘’
‘’ COPYRIGHT NOTICE
‘’ Copyright 1998-1999 Barry Dorrans All Rights Reserved.
‘’
‘’ CurrentUsers may be used and modified free of charge by anyone so
long
‘’ as this copyright notice and the comments above remain intact. By
using
‘’ this code you agree to indemnify Barry Dorrans from any liability
that
‘’ might arise from its use.
‘’
‘’ Selling the code for this program without prior written consent is
‘’ expressly forbidden. In other words, please ask first before you
try and
‘’ make money off of my program.
‘’
‘’ Obtain permission before redistributing this software over the
Inte.net or
‘’ in any other medium. In all cases copyright and header must remain
intact
%>
<html>
<title>Current User report</title>
<body bgcolor="#fffaf0">

<h1> Current User Report </h1>

<br>
<table border=0>
<tr><td><p><b>Remote Host</b></td>
<td><p><b>Browser</b></td></tr>
<%

DIM objADO, sDatabasePath, sConnection, sessionRecords
DIM userCount

userCount = 0

SET objADO = Server.CreateObject("ADODB.Connection")
sDatabasePath = Server.MapPath("/databases")
sConnection
= "filedsn="&sDatabasePath&"\readonly.dsn;DBQ="&sDatabasePath&"\sessio
ns.mdb;"
objADO.Open(sConnection)

SET sessionRecords = objADO.execute("select * from session;")

DO WHILE NOT sessionRecords.EOF
userCount = userCount + 1
%>
<tr><td><p><%=sessionRecords("Host")%></td>
<td><p><%=sessionRecords("BrowserType")%></td></tr>
<% sessionRecords.MoveNext
LOOP

sessionRecords.Close
objADO.close
SET sessionRecords = Nothing
SET objADO=Nothing

%>


Session变量的有效期默认为20分钟,可以通过下面来改变它的默认有效期:
Session.Timeout=(有效期的分钟数)

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网