Geekpedia Programming Tutorials






Geekpedia / Programming FAQ / ASP.NET / The name 'Session' does not exist in the current context

The name 'Session' does not exist in the current context



This error normally occurs when you are trying to access the value of a session variable such as Session["UserID"] and you're not doing that from a webform, usercontrol or a class that inherits from System.Web.UI.

In this situation you can still access the session variable, but using a different path.
For example to access a session variable named UserID you would normally use Session["UserID"]; however, if the error The name 'Session' does not exist in the current context is returned, use the following path for retrieving the value of the session variable:

HttpContext.Current.Session["UserID"];


by Andrew Pociu at Jan, 15 2006 - 08:24 | 14551 hits

nishshanka - Feb 14 2006 - 00:07

Thanks lot. you saved my time..
it is working nice


Jeff - May 16 2006 - 21:51

Amen, thank you, lifesaver...


semigeek - Jun 08 2006 - 01:45

Andrei u are the man!


Blake - Jun 09 2006 - 15:13

Great post, this has helped a ton in transition from ASP to ASP.NET. In addition, HttpContext.Current has all of the web objects you may need from your classes like Request, Reponse, etc.


KT - Jul 06 2006 - 11:02

Thanx a lot was looking for it.


Agustin - Dec 13 2006 - 12:05

Gorgeous POST!!!
Thanx


Ed - Dec 18 2006 - 19:21

Oh! Thank you very much.

there is God guiding me to your site


Fostec - Jan 01 2007 - 05:57

Thanks very much!


nikhil - Jan 08 2007 - 04:52

Great post, i had to struggle a lot till i saw your post. Thanks a lot


Jan - Jan 15 2007 - 00:23

Great this was what I needed


Fay - Feb 19 2007 - 05:03

Thank you Andrei, you're a star.


let me add to the co - Apr 05 2007 - 14:40

THANK YOU SO MUCH!!!!!!!!!!!!!!!!!!!!!!!!!


- Apr 18 2007 - 10:25

Great Help to me!


pranay - May 18 2007 - 04:19

Great Help!!! Thanks lots


- Jun 12 2007 - 10:58

Awesome Post, so easy yet so helpful!!


Tdog Moneyman - Jun 22 2007 - 18:08

This is better. I guess no one here has tried to access Session from a backing class? Don't suck the whole System.Web class into your new class though!!

System.Web.HttpContext.Current.Session["UserID"]


Pat Markland - Aug 30 2007 - 23:16

YES!!! Thank you!


Remo - Sep 21 2007 - 06:14

Thanks a lot, it helps me a lot


sKiLLer - Oct 08 2007 - 11:52

Excellent!


bbbbb - Nov 02 2007 - 02:40

Good!


matt - Nov 13 2007 - 06:48

Modern Day Hero.

THANKS!


Robot - Dec 06 2007 - 05:29

FANKoooooooooooooo!


xorit - Jan 06 2008 - 12:06

That did it. Saved me lots of time and frustration.


Poo - Mar 13 2008 - 05:28

Great ,,, thnx so much


J - May 10 2008 - 03:19

tht didnt work...



Add your comment:
Name:
Email:
Comment:
Please enter the Verification value character in the text box:
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Download

Latest Icons