Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 13, 2007 05:11 PM by preethi9
Apr 02, 2007 12:10 PM|LINK
I am developing an asp.net web site, using VB.Net as the core language, and have create a class file to store some global methods I use on a number of pages.
When I try to implement a session variable inside a class in this manner:
Public Class SessionVars
Public Sub initializeVars()
Session("UserID") = "SomeDefaultSetting"
I get an error "Session not declared". Suggesting that the class file sees this is a variable.
Any ideas how I might use Session Variables with a class file?
Apr 02, 2007 12:33 PM|LINK
Session is part of the HTTPContext and is derived from System.Web.
Add a reference to System.Web to the project (I'm assuming its just a class project and not in your Web project).
Then add the Imports and/or namespace out the Session object.
Apr 02, 2007 01:12 PM|LINK
Thanks for the reply I made the change and now it errors with
Reference to a non-shared member requires an object reference
Apr 02, 2007 01:16 PM|LINK
on what line?
Most likely it's just a matter of needing the Session object pathed out, to ensure you are using the Current HTTPContext.
Apr 02, 2007 01:24 PM|LINK
Perhaps I'm having a bad day but could you give me an example of a vb class (including the imports) where this would work? I'm not exactly sure what you're saying here. I'm very new to asp.net and I guess this is part of the problem...... [:$]
Apr 02, 2007 01:27 PM|LINK
Apr 02, 2007 01:34 PM|LINK
Thanks Curt got it now, works like a charm
Nov 05, 2007 01:18 PM|LINK
Dec 13, 2007 05:11 PM|LINK