newbie session state

  • Thread starter Thread starter Buz Waitz
  • Start date Start date
B

Buz Waitz

I'm trying to work with session variables for the first time. They seem to
save just fine as in

Session("TryThis") = localSomeValue

but when I try

localSomeValue = Session("TryThis")

Intellisense doesn't recognize "Session." I have the webconfig set
properely, I believe.

Help?

Thanks
 
Are you getting squiglies? If not, do not sweat it. If so, is this in a
class instead of an ASPX or CodeBehind page. If so, you have to make sure
you reference System.Web for the class.

To get something out of Session, you should explicitly convert:

localSomeValue = Convert.ToString(Session("SomeValue"))

Or, just ToString() for strings.

Does this help?

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************************************************
Think outside the box!
***************************************************************
 
Thank you, it is a class. I've put in the reference to system.web, but am
still getting the squiggles, even explicitly converting.

Thanks, though.
 
Hi Buz,

If you are coding in a certain util class rather than in the page's
codebehind or other ASP.NET components, you won't get the intellisene when
directly type "Session" because the Session is the buildin member of Page
or HttpContext. However, in dotnet, the HttpContext class has a
shared(static) property "Current" which hold the refernce to the current
request's Context. So if you want to retrieve the ASP.NET buildin objects
of the Request's context such as Session, Request, Response... you can make
use of the "Current" member as below:

HttpContext.Current.Session ...
HttpContext.Current.Request...
HttpContext.Current.Response....
....

For more detailed info on the HttpContext and the "Current" property,
please view the following reference in MSDN:

#HttpContext.Current Property
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebHttpContext
ClassCurrentTopic.asp?frame=true

#HttpContext Class
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebHttpContext
ClassTopic.asp?frame=true

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Thank you. That worked just fine. However, the links are no longer valid. I
got the idea though. Thanks!
 
Back
Top