2

是否可以从页面上下文之外获取会话值?是 vb.net 类吗?

4

2 回答 2

3

试试System.Web.HttpContext.Current.Session

于 2013-03-26T07:18:09.183 回答
0

我一直在使用这样的类(示例只有一个属性,但您可以设置您需要的属性)

Public Class MySession

    Private Sub New()
    End Sub

    Public Shared ReadOnly Property Current() As MySession
        Get
            Dim session As MySession = DirectCast(HttpContext.Current.Session("__MySession__"), MySession)
            If session Is Nothing Then
                session = New MySession()
                HttpContext.Current.Session("__MySession__") = session
            End If
            Return session
        End Get
    End Property

    Public Property IsAuthenticated As Boolean
End Class

像这样使用它

    <%
       If MySession.Current.IsAuthenticated Then
    %>
于 2013-03-26T07:38:14.690 回答