当前位置: 代码迷 >> VB Dotnet >> vb.net 有一段代码在vs2010 里边运行时间2ms,放到服务器iis7上的时候,运行时间4秒,求教 什么原因多
  详细解决方案

vb.net 有一段代码在vs2010 里边运行时间2ms,放到服务器iis7上的时候,运行时间4秒,求教 什么原因多

热度:71   发布时间:2016-04-25 02:11:51.0
vb.net 有一段代码在vs2010 里面运行时间2ms,放到服务器iis7上的时候,运行时间4秒,求教 什么原因多
 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是无意义的
  相关解决方案