Session variables

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I am writing some library routines to use in my asp.net pages. They need to
access my session variables, but I don't know what namespaces/libraries to
access to make it work. Asp.net already does that for you.

How do I access Session variables from my objects?

What refererence (using...) do I need as well as what .dll do I need in my
make file?

Thanks,

Tom
 
Tom,

You can use the HttpContext class. If you use the static Current
property on the HttpContext class, it will return your current HttpContext.
You can then use the Session property on the HttpContext to access the
current session.

Hope this helps.
 
string whatever = (string) this.Context.Session["whatever"];

--

Derek Davis
(e-mail address removed)

Nicholas Paldino said:
Tom,

You can use the HttpContext class. If you use the static Current
property on the HttpContext class, it will return your current
HttpContext. You can then use the Session property on the HttpContext to
access the current session.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tshad said:
I am writing some library routines to use in my asp.net pages. They need
to access my session variables, but I don't know what namespaces/libraries
to access to make it work. Asp.net already does that for you.

How do I access Session variables from my objects?

What refererence (using...) do I need as well as what .dll do I need in
my make file?

Thanks,

Tom
 
So in my Imports clause would I need:

imports System.Web.HttpContext

I also saw Imports System.Web.SessionState

If I put in the "imports System.Web.HttpContext", would I then do:

string whatever = (string) this.Session["whatever"];

Also, what .dll would I need in my make file - /r:system.web.dll and
/r:system.dll ?

Thanks,

Tom

carion1 said:
string whatever = (string) this.Context.Session["whatever"];

--

Derek Davis
(e-mail address removed)

Nicholas Paldino said:
Tom,

You can use the HttpContext class. If you use the static Current
property on the HttpContext class, it will return your current
HttpContext. You can then use the Session property on the HttpContext to
access the current session.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tshad said:
I am writing some library routines to use in my asp.net pages. They need
to access my session variables, but I don't know what
namespaces/libraries to access to make it work. Asp.net already does
that for you.

How do I access Session variables from my objects?

What refererence (using...) do I need as well as what .dll do I need in
my make file?

Thanks,

Tom
 
system.web will do. One the namespace is available, the code will compile.
Otherwise it won't.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



tshad said:
So in my Imports clause would I need:

imports System.Web.HttpContext

I also saw Imports System.Web.SessionState

If I put in the "imports System.Web.HttpContext", would I then do:

string whatever = (string) this.Session["whatever"];

Also, what .dll would I need in my make file - /r:system.web.dll and
/r:system.dll ?

Thanks,

Tom

carion1 said:
string whatever = (string) this.Context.Session["whatever"];

--

Derek Davis
(e-mail address removed)

Nicholas Paldino said:
Tom,

You can use the HttpContext class. If you use the static Current
property on the HttpContext class, it will return your current
HttpContext. You can then use the Session property on the HttpContext to
access the current session.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am writing some library routines to use in my asp.net pages. They need
to access my session variables, but I don't know what
namespaces/libraries to access to make it work. Asp.net already does
that for you.

How do I access Session variables from my objects?

What refererence (using...) do I need as well as what .dll do I need in
my make file?

Thanks,

Tom
 
Back
Top