【发布时间】:2012-03-08 19:42:45
【问题描述】:
我对 vb.net 很陌生,因为我更像是一名 PHP 开发人员,但无论如何。我已经构建了一个 Web 应用程序,但我的用户似乎正在共享同一个会话,这是我不想要的,也不明白为什么。我从模块中的全局属性访问存储所有会话信息的对象,这可能是原因吗?
代码如下:
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
【问题讨论】:
-
为什么使用静态类(模块)作为 Session 对象的存储库?静态意味着应用广泛。
mUserSession也是静态的,因此所有用户共享同一个会话。 -
啊...就像我说的,vb.net 的新手。我只是想要一种全局(非静态)方式来访问我的会话对象,而不是在整个地方重复相同的检查和访问。我的印象是模块只是全局可访问的函数存储空间,而不是静态的。
标签: asp.net vb.net session session-state