是否可以从页面上下文的外部获取会话值?是一个vb.net类?
答案 0 :(得分:3)
答案 1 :(得分: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
%>