我是很新的vb.net因爲我更是一個PHP開發人員,但無論如何的。我已經構建了一個Web應用程序,但我的用戶似乎正在共享我不想要的同一個會話,並且無法理解原因。我從一個模塊的全局屬性中訪問存儲所有會話信息的對象,這可能是原因嗎?VB.NET Web應用程序 - 不需要用戶會話共享
的代碼如下:你爲什麼要使用一個靜態類(模塊)作爲信息庫用於Session對象
Module SiteWide
Private mUserSession As New MyLib.User.UserSession
Public Property gUserSession() As MyLib.User.UserSession
Get
If Not HttpContext.Current Is Nothing AndAlso Not HttpContext.Current.Session Is Nothing Then
If Not HttpContext.Current.Session("user") Is Nothing Then
mUserSession = HttpContext.Current.Session("user")
End If
End If
Return mUserSession
End Get
Set(ByVal value As MyLib.User.UserSession)
mUserSession = value
If Not HttpContext.Current Is Nothing AndAlso Not HttpContext.Current.Session Is Nothing Then
HttpContext.Current.Session("user") = value
End If
End Set
End Property
End Module
爲什麼使用靜態類(Module)作爲Session對象的存儲庫?靜態意味着應用廣泛。 'mUserSession'也是隱式靜態的,因此所有的用戶共享同一個Session。 – 2012-02-17 12:01:01
啊...就像我剛纔說的,vb.net新手。我只想要一個全局(非靜態)的方式來訪問我的會話對象,而不是重複同樣的檢查和訪問。我的印象是一個模塊只是全局可訪問的功能存儲空間,而不是靜態的。 – James 2012-02-17 12:05:39