G
Greg Linwood
I'm having difficulty understanding Session state in ASP.Net. It's almost
embarrassing asking this as I've been using ASP since it was first released
& it really shouldn't be this hard to use - perhaps I'm just not very smart
or perhaps MS is making this too hard for us sql bunnies to understand - I
dunno, but I'd really appreciate someone explaining what I'm doing wrong
here & perhaps suggest a better approach..
I'm familiar with use of the old Session("variable") = value syntax. (also
very aware of scalability issues - so don't flame me on this - I'm just
trying to understand how the whole thing fits together here). I expected
things to work similarly with ASP.Net but I just can't get it to work easily
for me..
I'm trying to carry around a Session("login_id") type variable & would like
to access it via code-behind (.aspx.vb) modules as well as class (.vb)
modules. I can successfully set a variable in a Page_Load event from one
form (during postback) but after re-directing to another form, I get a nasty
error when trying to access the value:
Object reference not set to an instance of an object
Line 29: Dim LoginID As String
Line 30: LoginID = Session("LoginID").ToString
Source File: ... home.aspx.vb Line: 30
I've tried using HttpContext.Current.Session("LoginID").ToString but this
just gets the same problem.
Why do I get an Object reference not set error? Surely Session doesn't need
to be instanced does it?
I'd appreciate any help.
Regards,
Greg Linwood
SQL Server MVP
embarrassing asking this as I've been using ASP since it was first released
& it really shouldn't be this hard to use - perhaps I'm just not very smart
or perhaps MS is making this too hard for us sql bunnies to understand - I
dunno, but I'd really appreciate someone explaining what I'm doing wrong
here & perhaps suggest a better approach..
I'm familiar with use of the old Session("variable") = value syntax. (also
very aware of scalability issues - so don't flame me on this - I'm just
trying to understand how the whole thing fits together here). I expected
things to work similarly with ASP.Net but I just can't get it to work easily
for me..
I'm trying to carry around a Session("login_id") type variable & would like
to access it via code-behind (.aspx.vb) modules as well as class (.vb)
modules. I can successfully set a variable in a Page_Load event from one
form (during postback) but after re-directing to another form, I get a nasty
error when trying to access the value:
Object reference not set to an instance of an object
Line 29: Dim LoginID As String
Line 30: LoginID = Session("LoginID").ToString
Source File: ... home.aspx.vb Line: 30
I've tried using HttpContext.Current.Session("LoginID").ToString but this
just gets the same problem.
Why do I get an Object reference not set error? Surely Session doesn't need
to be instanced does it?
I'd appreciate any help.
Regards,
Greg Linwood
SQL Server MVP