| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 968 人关注过本帖
标题:各位请指教:我想在global.asax统计登录网站的人数,程序代码如下,但有时如果 ...
取消只看楼主 加入收藏
iloveyou520
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-6-2
收藏
 问题点数:0 回复次数:1 
各位请指教:我想在global.asax统计登录网站的人数,程序代码如下,但有时如果不是从首
各位请指教:我想在global.asax统计登录网站的人数,程序代码如下,但有时如果不是从首页登录的时候这里保存的数据库路径就会出错,请问如何解决这一问题??

'以下导入名称空间,注意这里是imports,不是import。
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls '因为使用web控件,所以导入
Imports System.Data
Imports System.Data.OleDb
Imports System.DateTime
Imports System.Configuration '因为使用Now(),所以要导入
Imports Microsoft.VisualBasic
Imports System.IO
Imports System.Web.UI.HtmlControls
Public Class Global: Inherits HttpApplication


protected sub Application_Start(sender As Object,e As EventArgs)
Application("strcon")="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("##2014##123###/##sffr20#11#")
DeleteAllUser()
End sub


Public Sub DeleteAllUser()
dim conn As New OleDbConnection(Application("strcon").ToString())
Dim strSq = "Delete from OnlineUsers1 Where UserId<>'大家'"
Dim cmd As New OleDbCommand(strSq, conn)
conn.Open()
cmd.ExecuteNonQuery() '删除记录
conn.Close()
End Sub


protected Sub Session_onStart(sender As Object,E As EventArgs)
'每一个客户登录时触发该事件
dim conn As New OleDbConnection(Application("strcon").ToString()) '使用了私有变量的值
'建立Command对象,注意这里使用了含有参数的SQL语句
dim IP as string
ip= Request.ServerVariables("REMOTE_ADDR")
Response.cookies("IPAddress").value=""
'Response.Cookies("ip").Expires = DateTime.Now.AddDays(1)
Dim Sql1 As String = "Select Count(*) As total From OnlineUsers Where ip='" & IP & "' and txtday = #" & today() & "#"
Dim cmd1 As New OleDbCommand(Sql1, conn) '建立Command对象
conn.Open()
Dim intTotal As Integer = cmd1.ExecuteScalar()
If intTotal > 0 Then
conn.Close() '该条件表示该用户名存在
Dim strSq As String = "Insert Into OnlineUsers(SessionId,UserId,LogInTime,IsOnline,txtday) Values('" & Session.SessionId & "','过客',#" & Now() & "#,True,#" & today() & "#)"
Dim cmd As New OleDbCommand(strSq, conn)
'下面执行操作
conn.open()
cmd.ExecuteNonQuery()
else
conn.close()
dim txta = datetime.today.month
Dim Sql2 As String = "Insert Into OnlineUsers(SessionId,UserId,LogInTime,IsOnline,ip,txtday,txtmonth) Values('" & Session.SessionId & "','过客',#" & Now() & "#,True,'" & IP & "',#" & today() & "#,'" & txta & "')"
Dim cmd2 As New OleDbCommand(Sql2, conn)
'下面执行操作
conn.open()
cmd2.ExecuteNonQuery()
conn.close()
end if
End Sub


sub Application_BeginRequest(sender As Object,e As EventArgs)
End Sub
Sub Application_AuthenticateRequest(sender As Object, e As EventArgs)
End Sub
Sub Application_Error(sender As Object,e As EventArgs)
End Sub


protected Sub Session_OnEnd(Sender As Object, E As EventArgs)
dim conn As New OleDbConnection(Application("strcon").ToString())
'每一个客户退出登录时触发该事件
Dim strSql As String = "Update OnlineUsers Set IsOnline=False,LogOutTime=#" & Now() & "# Where SessionId='" & Session.SessionId & "' And IsOnline=True"
Dim cmd As New OleDbCommand(strSql, conn)
'下面执行操作
conn.open()
cmd.ExecuteNonQuery()
conn.close()
DeleteUser(Session("UserId"))
UserGo(Session("UserId"), Session("IP"), Session("ChatRoom"))
End Sub


Public Sub DeleteUser(strUserId As String)
dim conn As New OleDbConnection(Application("strcon").ToString())
Dim strSql = "Delete from OnlineUsers1 Where UserId='" & strUserId & "'"
Dim cmd As New OleDbCommand(strSql, conn)
conn.Open()
cmd.ExecuteNonQuery() '删除记录
conn.Close()
End Sub

搜索更多相关主题的帖子: asax global 代码 指教 
2006-06-02 15:55
iloveyou520
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-6-2
收藏
得分:0 
怎么没人回答我的问题啊?
2006-06-02 23:30
快速回复:各位请指教:我想在global.asax统计登录网站的人数,程序代码如下,但有时 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017221 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved