Using Session State in Public Class in ASP.NET?

Posted by davemackey on Stack Overflow See other posts from Stack Overflow or by davemackey
Published on 2010-04-22T13:01:11Z Indexed on 2010/04/22 13:03 UTC
Read the original article Hit count: 194

Filed under:
|
|
|

I'm trying to move some reusable portions of code into a class. This is working okay except when I attempt to use Session within this class. I get an error:

"Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class."

My code looks something like this:

Public Class webHousing
    Inherits System.Web.UI.Page
  Public Sub GetUserInfo()
    Dim x as String
    x = 10
    Session("x")= x
  End Sub
End Class

I've simplified this code significantly - but the basic problem is present - trying to set a session value from within a class. I found the following MSDN article1 but don't believe Public/Shared can be used on Session?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about session