Reputation:
I have a session
for storing the id
of the user
Session("id") = "123"
I am using a shared sub
which accessing the session variable, my code is:
Public Shared Sub check_session()
MsgBox(Session("id"))
End Sub
it shows the error message : cannot refer to an instance member from a class within a shared sub
My question is that : how can i access a session variable inside a shared sub, Is it possible to attach another user id to the session variable?
thanks
Upvotes: 5
Views: 2428
Reputation: 1326
According to the answer provided by Vignesh Kumar you can access session variable in shared sub. here i provide answer for second question. your shared function for handle session is like the following:
Public Shared Sub check_session()
MsgBox("Old Session:" & HttpContext.Current.Session("id"))
HttpContext.Current.Session("id") = HttpContext.Current.Session("id") & "567"
MsgBox("new Session:" & HttpContext.Current.Session("id"))
End Sub
Upvotes: 2