Public Shared Sub RegisterUser(ByVal pUserName As String)
Dim userInfo As New SessionUserInfo()
HttpContext.Current.Session(ESessionKeys.UserInformation) = userInfo
Dim tempHash As IDictionary = DirectCast(HttpContext.Current.Application("SessionList"), Hashtable)
If tempHash Is Nothing Then
tempHash = New Hashtable
HttpContext.Current.Application("SessionList") = tempHash
End If
If Not tempHash.ContainsKey(HttpContext.Current.Session.SessionID) Then
tempHash.Add(HttpContext.Current.Session.SessionID, HttpContext.Current.Session)
'lock the application object and increment session total
SyncLock HttpContext.Current.Application
Dim i As Integer = CInt(HttpContext.Current.Application("SessionsTotal"))
i += 1
HttpContext.Current.Application("SessionsTotal") = i
End SyncLock
End If
'if the userInfo object is not null and the session is new
userInfo.UserAgent = HttpContext.Current.Request.UserAgent
Try
userInfo.HostName = System.Net.Dns.GetHostEntry(HttpContext.Current.Request.UserHostAddress).HostName
userInfo.HostAddress = HttpContext.Current.Request.UserHostAddress
Catch ex As Exception
userInfo.HostName = HttpContext.Current.Request.ServerVariables("REMOTE_HOST")
userInfo.HostAddress = HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
End Try
userInfo.UserName = pUserName.Trim
userInfo.LoginTime = Now.ToGuiDateTimeString
End Sub
------解决思路----------------------
你这个程序我看不出来什么问题,只能靠猜。
Application这个,不好随意锁的吧,因为所有用户都会访问到它,
------解决思路----------------------
及其环境,网络环境都不一样
------解决思路----------------------
System.Net.Dns.GetHostEntry()
如果不在一个网段,或权限不允许,就要超时才出来,要等较长时间
用这个方法拿用户机器名,在Internet是无意义的