Showing posts with label session. Show all posts
Showing posts with label session. Show all posts

Saturday, March 31, 2012

Trimming

I am trying to trim a session variable to get the last three characters.Here is the code:

Dim CancelTrim()AsChar = {"","cc9"}

If Session("confirm").trimend(CancelTrim) ="ca1"Then

Label1.Text ="it was cancelled"

EndIf

It's not working though, go figure. So, how would I get these to trim off the last three characters so I can do what I need to do?

Thanks

Hello,

so what does it return from ther TrimEnd call? TrimEnd trims from the end of the string, so isn't that from the wrong direction if you want the last three characters? So maybe TrimStart would work better?

On the other hand, couldn't you write something like:

Dim ConfirmStringAs String = Cstr(Session("confirm"))Dim LastThreeCharsAs String = ConfirmString.Substring(ConfirmString.Length - 3)If LastThreeChars ="ca1"Then'CheckEnd If

Monday, March 26, 2012

trouble retrieving data from ASPState Database

I'm trying to put together a web form that lists all current session informa
tion. The session info is stored in SQL server database (ASPState) and I'm t
rying to retreive and display using a SQLDataReader. I seem to have no troub
le querying the "ASPStateTe
mpSessions" table but when I try to write it to the page, I throw an excepti
on that basically says that there is no data to display. Is there some speci
al method you must use when performing this sort of task?
The code is as follows:
----
dim cn as new SqlConnection(ConfigurationSettings.AppSetting ("ASPState").to
String())
cn.Open()
dim cmd as new SqlCommand("select * from ASPStateTempSessions where TimeOut
= 40", cn)
dim dr as SqlDataReader
dr = cmd.ExecuteReader()
Response.Write(dr("Locked"))
----
The exception content is as follows:
System.InvalidOperationException: Invalid attempt to read when no data is pr
esent. at System.Data.SqlClient.SqlDataReader.PrepareRecord(Int32 i) at Syst
em.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at System.Data.SqlClient.S
qlDataReader.get_Item(Strin
g name) at ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) i
n C:\Inetpub\wwwroot\onehour\AgreementList
ing.aspx:line 82when using a datareader, you have to first call the "read" method.
dr = cmd.ExecuteReader()
dr.read()
Response.Write(dr("Locked"))
OR to get all rows:
do while dr.read()
Response.Write(dr("Locked"))
loop (i think)
"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:BBA23A84-4649-4967-8AA3-6D98648C0555@.microsoft.com...
> I'm trying to put together a web form that lists all current session
information. The session info is stored in SQL server database (ASPState)
and I'm trying to retreive and display using a SQLDataReader. I seem to have
no trouble querying the "ASPStateTempSessions" table but when I try to write
it to the page, I throw an exception that basically says that there is no
data to display. Is there some special method you must use when performing
this sort of task?
> The code is as follows:
> ----
> dim cn as new SqlConnection(ConfigurationSettings.AppSetting
("ASPState").toString())
> cn.Open()
> dim cmd as new SqlCommand("select * from ASPStateTempSessions where
TimeOut = 40", cn)
> dim dr as SqlDataReader
> dr = cmd.ExecuteReader()
> Response.Write(dr("Locked"))
>
> ----
> The exception content is as follows:
> System.InvalidOperationException: Invalid attempt to read when no data is
present. at System.Data.SqlClient.SqlDataReader.PrepareRecord(Int32 i) at
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at
System.Data.SqlClient.SqlDataReader.get_Item(String name) at
ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in
C:\Inetpub\wwwroot\onehour\AgreementList
ing.aspx:line 82
Boy, am I a dope! I thought datareader.read worked along the lines of record
set.EOF. I thought it was a simple boolean property that told you if any rec
ords were returned or not. But it is actually a method that returns a boolea
n. I guess you learn someth
ing new every day. Thanks much!!
"mark" wrote:

> when using a datareader, you have to first call the "read" method.
> dr = cmd.ExecuteReader()
> dr.read()
> Response.Write(dr("Locked"))
> OR to get all rows:
> do while dr.read()
> Response.Write(dr("Locked"))
> loop (i think)
>
>
> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
> news:BBA23A84-4649-4967-8AA3-6D98648C0555@.microsoft.com...
> information. The session info is stored in SQL server database (ASPState)
> and I'm trying to retreive and display using a SQLDataReader. I seem to ha
ve
> no trouble querying the "ASPStateTempSessions" table but when I try to wri
te
> it to the page, I throw an exception that basically says that there is no
> data to display. Is there some special method you must use when performing
> this sort of task?
> ("ASPState").toString())
> TimeOut = 40", cn)
> present. at System.Data.SqlClient.SqlDataReader.PrepareRecord(Int32 i) at
> System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at
> System.Data.SqlClient.SqlDataReader.get_Item(String name) at
> ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in
> C:\Inetpub\wwwroot\onehour\AgreementList
ing.aspx:line 82
>
>

Saturday, March 24, 2012

trouble retrieving data from ASPState Database

I'm trying to put together a web form that lists all current session information. The session info is stored in SQL server database (ASPState) and I'm trying to retreive and display using a SQLDataReader. I seem to have no trouble querying the "ASPStateTempSessions" table but when I try to write it to the page, I throw an exception that basically says that there is no data to display. Is there some special method you must use when performing this sort of task?
The code is as follows:
------------------
dim cn as new SqlConnection(ConfigurationSettings.AppSetting ("ASPState").toString())
cn.Open()
dim cmd as new SqlCommand("select * from ASPStateTempSessions where TimeOut = 40", cn)
dim dr as SqlDataReader
dr = cmd.ExecuteReader()
Response.Write(dr("Locked"))

------------------
The exception content is as follows:

System.InvalidOperationException: Invalid attempt to read when no data is present. at System.Data.SqlClient.SqlDataReader.PrepareRecord( Int32 i) at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at System.Data.SqlClient.SqlDataReader.get_Item(Strin g name) at ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in C:\Inetpub\wwwroot\onehour\AgreementListing.aspx:l ine 82when using a datareader, you have to first call the "read" method.

dr = cmd.ExecuteReader()
dr.read()
Response.Write(dr("Locked"))

OR to get all rows:

do while dr.read()
Response.Write(dr("Locked"))
loop (i think)

"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:BBA23A84-4649-4967-8AA3-6D98648C0555@.microsoft.com...
> I'm trying to put together a web form that lists all current session
information. The session info is stored in SQL server database (ASPState)
and I'm trying to retreive and display using a SQLDataReader. I seem to have
no trouble querying the "ASPStateTempSessions" table but when I try to write
it to the page, I throw an exception that basically says that there is no
data to display. Is there some special method you must use when performing
this sort of task?
> The code is as follows:
> ------------------
> dim cn as new SqlConnection(ConfigurationSettings.AppSetting
("ASPState").toString())
> cn.Open()
> dim cmd as new SqlCommand("select * from ASPStateTempSessions where
TimeOut = 40", cn)
> dim dr as SqlDataReader
> dr = cmd.ExecuteReader()
> Response.Write(dr("Locked"))
>
> ------------------
> The exception content is as follows:
> System.InvalidOperationException: Invalid attempt to read when no data is
present. at System.Data.SqlClient.SqlDataReader.PrepareRecord( Int32 i) at
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at
System.Data.SqlClient.SqlDataReader.get_Item(Strin g name) at
ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in
C:\Inetpub\wwwroot\onehour\AgreementListing.aspx:l ine 82
Boy, am I a dope! I thought datareader.read worked along the lines of recordset.EOF. I thought it was a simple boolean property that told you if any records were returned or not. But it is actually a method that returns a boolean. I guess you learn something new every day. Thanks much!!

"mark" wrote:

> when using a datareader, you have to first call the "read" method.
> dr = cmd.ExecuteReader()
> dr.read()
> Response.Write(dr("Locked"))
> OR to get all rows:
> do while dr.read()
> Response.Write(dr("Locked"))
> loop (i think)
>
>
> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
> news:BBA23A84-4649-4967-8AA3-6D98648C0555@.microsoft.com...
> > I'm trying to put together a web form that lists all current session
> information. The session info is stored in SQL server database (ASPState)
> and I'm trying to retreive and display using a SQLDataReader. I seem to have
> no trouble querying the "ASPStateTempSessions" table but when I try to write
> it to the page, I throw an exception that basically says that there is no
> data to display. Is there some special method you must use when performing
> this sort of task?
> > The code is as follows:
> > ------------------
> > dim cn as new SqlConnection(ConfigurationSettings.AppSetting
> ("ASPState").toString())
> > cn.Open()
> > dim cmd as new SqlCommand("select * from ASPStateTempSessions where
> TimeOut = 40", cn)
> > dim dr as SqlDataReader
> > dr = cmd.ExecuteReader()
> > Response.Write(dr("Locked"))
> > ------------------
> > The exception content is as follows:
> > System.InvalidOperationException: Invalid attempt to read when no data is
> present. at System.Data.SqlClient.SqlDataReader.PrepareRecord( Int32 i) at
> System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at
> System.Data.SqlClient.SqlDataReader.get_Item(Strin g name) at
> ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in
> C:\Inetpub\wwwroot\onehour\AgreementListing.aspx:l ine 82
>

Thursday, March 22, 2012

Trouble With Session State

Hello,
I am having trouble with session state in my asp.net 1.1 C# web app. I
am trying to program either a popup box warning of expiration, or I
may do a redirect to the home page upon expiration.
But I can't seem to get started, because I am getting values that I do
not understand. In IIS settings, I stopped my website/app and went
into the properties for it and selected the "Home Directory" tab. Then
I clicked the "Configuration" button and selected the "Options" tab.
Then under the "Application Configuration" group, I verified that the
box for "Enable session state" was checked. Then I changed the value
to "2" (just for testing). I then saved and restarted my website.
Then I opened the site in Visual Studio.net and went into the
web.config file and changed the forms authentication timeout value to
"1" (again, just for testing).
Then when I ran my code, in debug mode/step through, I can see that
the value being returned for "this.Session.Timeout" is "15"? What's
going on here? I thought that when I set the value in IIS, it would
make it 2, but that didn't happen? Where is this number coming from?
How can I change/control it?
Your help is much appreciated.
JP"Joey" <joey.powell@.topscene.com> wrote in message
news:1176914556.144456.278850@.b75g2000hsg.googlegroups.com...
> Hello,
> I am having trouble with session state in my asp.net 1.1 C# web app. I
> am trying to program either a popup box warning of expiration, or I
> may do a redirect to the home page upon expiration.
> But I can't seem to get started, because I am getting values that I do
> not understand. In IIS settings, I stopped my website/app and went
> into the properties for it and selected the "Home Directory" tab. Then
> I clicked the "Configuration" button and selected the "Options" tab.
> Then under the "Application Configuration" group, I verified that the
> box for "Enable session state" was checked. Then I changed the value
> to "2" (just for testing). I then saved and restarted my website.
I believe these values are for classic ASP, not for ASP.NET.
--
John Saunders [MVP]
On Apr 18, 12:34 pm, "John Saunders [MVP]" <john.saunders at
trizetto.com> wrote:
> "Joey" <joey.pow...@.topscene.com> wrote in message
> news:1176914556.144456.278850@.b75g2000hsg.googlegroups.com...
>
>
>
> I believe these values are for classic ASP, not for ASP.NET.
> --
> John Saunders [MVP]
So how does one set session timeout for asp.net?
Use the sessionState entry in Web.Config...
--
Brad
"Software is like melted pudding..."
"Joey" wrote:

> On Apr 18, 12:34 pm, "John Saunders [MVP]" <john.saunders at
> trizetto.com> wrote:
> So how does one set session timeout for asp.net?
>
On Apr 18, 12:54 pm, Brad Roberts <BradRoberts56noj...@.hotmail.com>
wrote:
> Use the sessionState entry in Web.Config...
> --
> Brad
> "Software is like melted pudding..."
>
> "Joey" wrote:
>
>
>
>
>
>
>
> - Show quoted text -
Thanks

Tuesday, March 13, 2012

Trouble With Session State

Hello,

I am having trouble with session state in my asp.net 1.1 C# web app. I
am trying to program either a popup box warning of expiration, or I
may do a redirect to the home page upon expiration.

But I can't seem to get started, because I am getting values that I do
not understand. In IIS settings, I stopped my website/app and went
into the properties for it and selected the "Home Directory" tab. Then
I clicked the "Configuration" button and selected the "Options" tab.
Then under the "Application Configuration" group, I verified that the
box for "Enable session state" was checked. Then I changed the value
to "2" (just for testing). I then saved and restarted my website.

Then I opened the site in Visual Studio.net and went into the
web.config file and changed the forms authentication timeout value to
"1" (again, just for testing).

Then when I ran my code, in debug mode/step through, I can see that
the value being returned for "this.Session.Timeout" is "15"? What's
going on here? I thought that when I set the value in IIS, it would
make it 2, but that didn't happen? Where is this number coming from?
How can I change/control it?

Your help is much appreciated.

JP"Joey" <joey.powell@.topscene.comwrote in message
news:1176914556.144456.278850@.b75g2000hsg.googlegr oups.com...

Quote:

Originally Posted by

Hello,
>
I am having trouble with session state in my asp.net 1.1 C# web app. I
am trying to program either a popup box warning of expiration, or I
may do a redirect to the home page upon expiration.
>
But I can't seem to get started, because I am getting values that I do
not understand. In IIS settings, I stopped my website/app and went
into the properties for it and selected the "Home Directory" tab. Then
I clicked the "Configuration" button and selected the "Options" tab.
Then under the "Application Configuration" group, I verified that the
box for "Enable session state" was checked. Then I changed the value
to "2" (just for testing). I then saved and restarted my website.


I believe these values are for classic ASP, not for ASP.NET.
--

John Saunders [MVP]
On Apr 18, 12:34 pm, "John Saunders [MVP]" <john.saunders at
trizetto.comwrote:

Quote:

Originally Posted by

"Joey" <joey.pow...@.topscene.comwrote in message
>
news:1176914556.144456.278850@.b75g2000hsg.googlegr oups.com...
>

Quote:

Originally Posted by

Hello,


>

Quote:

Originally Posted by

I am having trouble with session state in my asp.net 1.1 C# web app. I
am trying to program either a popup box warning of expiration, or I
may do a redirect to the home page upon expiration.


>

Quote:

Originally Posted by

But I can't seem to get started, because I am getting values that I do
not understand. In IIS settings, I stopped my website/app and went
into the properties for it and selected the "Home Directory" tab. Then
I clicked the "Configuration" button and selected the "Options" tab.
Then under the "Application Configuration" group, I verified that the
box for "Enable session state" was checked. Then I changed the value
to "2" (just for testing). I then saved and restarted my website.


>
I believe these values are for classic ASP, not for ASP.NET.
--
>
John Saunders [MVP]


So how does one set session timeout for asp.net?
Use the sessionState entry in Web.Config...
--
Brad

"Software is like melted pudding..."

"Joey" wrote:

Quote:

Originally Posted by

On Apr 18, 12:34 pm, "John Saunders [MVP]" <john.saunders at
trizetto.comwrote:

Quote:

Originally Posted by

"Joey" <joey.pow...@.topscene.comwrote in message

news:1176914556.144456.278850@.b75g2000hsg.googlegr oups.com...

Quote:

Originally Posted by

Hello,


Quote:

Originally Posted by

I am having trouble with session state in my asp.net 1.1 C# web app. I
am trying to program either a popup box warning of expiration, or I
may do a redirect to the home page upon expiration.


Quote:

Originally Posted by

But I can't seem to get started, because I am getting values that I do
not understand. In IIS settings, I stopped my website/app and went
into the properties for it and selected the "Home Directory" tab. Then
I clicked the "Configuration" button and selected the "Options" tab.
Then under the "Application Configuration" group, I verified that the
box for "Enable session state" was checked. Then I changed the value
to "2" (just for testing). I then saved and restarted my website.


I believe these values are for classic ASP, not for ASP.NET.
--

John Saunders [MVP]


>
So how does one set session timeout for asp.net?
>
>


On Apr 18, 12:54 pm, Brad Roberts <BradRoberts56noj...@.hotmail.com>
wrote:

Quote:

Originally Posted by

Use the sessionState entry in Web.Config...
--
Brad
>
"Software is like melted pudding..."
>
>
>
"Joey" wrote:

Quote:

Originally Posted by

On Apr 18, 12:34 pm, "John Saunders [MVP]" <john.saunders at
trizetto.comwrote:

Quote:

Originally Posted by

"Joey" <joey.pow...@.topscene.comwrote in message


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>news:1176914556.144456.278850@.b75g2000hsg.googlegr oups.com...


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Hello,


>

Quote:

Originally Posted by

Quote:

Originally Posted by

I am having trouble with session state in my asp.net 1.1 C# web app. I
am trying to program either a popup box warning of expiration, or I
may do a redirect to the home page upon expiration.


>

Quote:

Originally Posted by

Quote:

Originally Posted by

But I can't seem to get started, because I am getting values that I do
not understand. In IIS settings, I stopped my website/app and went
into the properties for it and selected the "Home Directory" tab. Then
I clicked the "Configuration" button and selected the "Options" tab.
Then under the "Application Configuration" group, I verified that the
box for "Enable session state" was checked. Then I changed the value
to "2" (just for testing). I then saved and restarted my website.


>

Quote:

Originally Posted by

Quote:

Originally Posted by

I believe these values are for classic ASP, not for ASP.NET.
--


>

Quote:

Originally Posted by

Quote:

Originally Posted by

John Saunders [MVP]


>

Quote:

Originally Posted by

So how does one set session timeout for asp.net?- Hide quoted text -


>
- Show quoted text -


Thanks

Trouble With UrlReferrer

I'm trying to store a session variable to store the filename of the page where the user was before the current one.

The reasoning is that I'm trying to store the value so that if a users session times out, I have the redirected to the logon page. Once they've logged back in I'd like to automatically take them back to the page where they were before.

I've tried using Session("ref")=Request.UrlReferrer to store the value. To test that I have the referring page I've created a label and assigned it the value of Session("Ref") by using lblReferrer.Text=Session("ref").

At first I was just getting a nothing where I exprected to see the referrer on the page. Today it's throwing an error saying can't convert a Uri to a String.

I've had a look at the documentation for Uri's but can't see a way to get just the referrers url.

Im I going about this the wrong way, or is it something basic I've missed?

Thanks
JasonSession("ref")=Request.UrlReferrer.ToString()
I did have .ToString() in the code at some stage, but I obviously in the wrong place.

In any case, you've solved my problem. Thanks for your help.
Jason

Trouble with using Session state

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 MVPwhen you transfer to another page, it isn't gauranteed to occur on the same
calling thread so all your state information, including session is discarded
and a new session built up to service the transfer call. If you want to
return state, there is an overloaded function parameter which enables you to
do so. Server.Transfer(page, bPreserveForm) set this to true and you will be
alright. the default is false. Same deal for redirect.

regards

--

----
Got TidBits?
Get it here: www.networkip.net/tidbits
"Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote in
message news:OcFr9EMsDHA.1884@.TK2MSFTNGP10.phx.gbl...
> 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
Thanks Alvin - but that didn't work.

I changed my Response.Redirect to a Server.Transfer(page, True) and I still
get the same error...

I noticed that the bPreserveForm argument seems only to apply to QueryString
& Form state. I want to preserve variable values in Session state, similarly
to the manner in which ASP Session worked. Is this possible in ASP.Net?
Perhaps there's simply some setting I'm not getting right or something..

Regards,
Greg Linwood
SQL Server MVP

"Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com> wrote in
message news:ePvc9KMsDHA.2304@.tk2msftngp13.phx.gbl...
> when you transfer to another page, it isn't gauranteed to occur on the
same
> calling thread so all your state information, including session is
discarded
> and a new session built up to service the transfer call. If you want to
> return state, there is an overloaded function parameter which enables you
to
> do so. Server.Transfer(page, bPreserveForm) set this to true and you will
be
> alright. the default is false. Same deal for redirect.
> regards
> --
>
> ----
> Got TidBits?
> Get it here: www.networkip.net/tidbits
> "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote in
> message news:OcFr9EMsDHA.1884@.TK2MSFTNGP10.phx.gbl...
> > 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
Try server.transfer(page.aspx, true).
Are you transferring to a page hosted in the application directory? That
should work otherwise the problem lies elsewhere.

regards

--

----
Got TidBits?
Get it here: www.networkip.net/tidbits
"Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote in
message news:efMJYVMsDHA.640@.tk2msftngp13.phx.gbl...
> Thanks Alvin - but that didn't work.
> I changed my Response.Redirect to a Server.Transfer(page, True) and I
still
> get the same error...
> I noticed that the bPreserveForm argument seems only to apply to
QueryString
> & Form state. I want to preserve variable values in Session state,
similarly
> to the manner in which ASP Session worked. Is this possible in ASP.Net?
> Perhaps there's simply some setting I'm not getting right or something..
> Regards,
> Greg Linwood
> SQL Server MVP
> "Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com> wrote in
> message news:ePvc9KMsDHA.2304@.tk2msftngp13.phx.gbl...
> > when you transfer to another page, it isn't gauranteed to occur on the
> same
> > calling thread so all your state information, including session is
> discarded
> > and a new session built up to service the transfer call. If you want to
> > return state, there is an overloaded function parameter which enables
you
> to
> > do so. Server.Transfer(page, bPreserveForm) set this to true and you
will
> be
> > alright. the default is false. Same deal for redirect.
> > regards
> > --
> > ----
> > Got TidBits?
> > Get it here: www.networkip.net/tidbits
> > "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote
in
> > message news:OcFr9EMsDHA.1884@.TK2MSFTNGP10.phx.gbl...
> > > 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
> >
hmm - that's what I did..

Perhaps I'm stuffing something up in my config or somewhere else in my
code.. I'll keep on debugging & try to identify whatever.. :c/

Regards,
Greg Linwood
SQL Server MVP

"Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com> wrote in
message news:#n#vhfMsDHA.1996@.TK2MSFTNGP09.phx.gbl...
> Try server.transfer(page.aspx, true).
> Are you transferring to a page hosted in the application directory? That
> should work otherwise the problem lies elsewhere.
> regards
> --
>
> ----
> Got TidBits?
> Get it here: www.networkip.net/tidbits
> "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote in
> message news:efMJYVMsDHA.640@.tk2msftngp13.phx.gbl...
> > Thanks Alvin - but that didn't work.
> > I changed my Response.Redirect to a Server.Transfer(page, True) and I
> still
> > get the same error...
> > I noticed that the bPreserveForm argument seems only to apply to
> QueryString
> > & Form state. I want to preserve variable values in Session state,
> similarly
> > to the manner in which ASP Session worked. Is this possible in ASP.Net?
> > Perhaps there's simply some setting I'm not getting right or something..
> > Regards,
> > Greg Linwood
> > SQL Server MVP
> > "Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com> wrote
in
> > message news:ePvc9KMsDHA.2304@.tk2msftngp13.phx.gbl...
> > > when you transfer to another page, it isn't gauranteed to occur on the
> > same
> > > calling thread so all your state information, including session is
> > discarded
> > > and a new session built up to service the transfer call. If you want
to
> > > return state, there is an overloaded function parameter which enables
> you
> > to
> > > do so. Server.Transfer(page, bPreserveForm) set this to true and you
> will
> > be
> > > alright. the default is false. Same deal for redirect.
> > > > regards
> > > > --
> > > > > ----
> > > Got TidBits?
> > > Get it here: www.networkip.net/tidbits
> > > "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote
> in
> > > message news:OcFr9EMsDHA.1884@.TK2MSFTNGP10.phx.gbl...
> > > > 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
> > > > > >
I think I may have an explanation:

I think that my code: Session("LoginID").ToString breaks if "LoginID" is not
in the HttpContext.Current.Session.Keys collection because there is no
object to call .ToString against.

Does this sound like a fair explanation? If so, how does one code
defensively around this issue without writing copious amounts of spag code
to handle session variables instances not being present?

Regards,
Greg Linwood
SQL Server MVP

"Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote in
message news:uscsIZNsDHA.560@.TK2MSFTNGP11.phx.gbl...
> hmm - that's what I did..
> Perhaps I'm stuffing something up in my config or somewhere else in my
> code.. I'll keep on debugging & try to identify whatever.. :c/
> Regards,
> Greg Linwood
> SQL Server MVP
> "Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com> wrote in
> message news:#n#vhfMsDHA.1996@.TK2MSFTNGP09.phx.gbl...
> > Try server.transfer(page.aspx, true).
> > Are you transferring to a page hosted in the application directory? That
> > should work otherwise the problem lies elsewhere.
> > regards
> > --
> > ----
> > Got TidBits?
> > Get it here: www.networkip.net/tidbits
> > "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote
in
> > message news:efMJYVMsDHA.640@.tk2msftngp13.phx.gbl...
> > > Thanks Alvin - but that didn't work.
> > > > I changed my Response.Redirect to a Server.Transfer(page, True) and I
> > still
> > > get the same error...
> > > > I noticed that the bPreserveForm argument seems only to apply to
> > QueryString
> > > & Form state. I want to preserve variable values in Session state,
> > similarly
> > > to the manner in which ASP Session worked. Is this possible in
ASP.Net?
> > > Perhaps there's simply some setting I'm not getting right or
something..
> > > > Regards,
> > > Greg Linwood
> > > SQL Server MVP
> > > > "Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com> wrote
> in
> > > message news:ePvc9KMsDHA.2304@.tk2msftngp13.phx.gbl...
> > > > when you transfer to another page, it isn't gauranteed to occur on
the
> > > same
> > > > calling thread so all your state information, including session is
> > > discarded
> > > > and a new session built up to service the transfer call. If you want
> to
> > > > return state, there is an overloaded function parameter which
enables
> > you
> > > to
> > > > do so. Server.Transfer(page, bPreserveForm) set this to true and you
> > will
> > > be
> > > > alright. the default is false. Same deal for redirect.
> > > > > > regards
> > > > > > --
> > > > > > > > ----
> > > > Got TidBits?
> > > > Get it here: www.networkip.net/tidbits
> > > > "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com>
wrote
> > in
> > > > message news:OcFr9EMsDHA.1884@.TK2MSFTNGP10.phx.gbl...
> > > > > 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
> > > > > > > > > > > >
I too have been having problems with Session Variables at some servers--they
do not persist after, say, 20 seconds. But your problem is different.

And your code produces no problem when tested on my computer--the session
variable displays fine after a server.transfer or response.redirect.

What do you have in your web.config file as regards session state. Here is
what I have (watch word wrap).

<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="60"
/
What is this "nasty error" you are receiving?

"Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote in
message news:OcFr9EMsDHA.1884@.TK2MSFTNGP10.phx.gbl...
> 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
It will break with a null reference exception if login_id isn't there like
you said. Before touching session variables you should always test:
if(Session("login_id") != null) blah blah blah. But that doesn't explain why
it isn't there after the transfer in the first place. I've written a small
demo with a transfer and redirect. No matter how you transfer, session
variables will still be around unless you explicitly clear them. Are you
clearing it somewhere after the transfer? Otherwise, you will need to
examine your IIS settings adjusting the recycle properties as needed.

One more thing you can try is to put code in you session end event to
populate a static variable. Then try to read this variable on the page you
transferred to. Session end should never be called under these
circumstances, otherwise it is the reason for your lost session variables.

Regards

--

----
Got TidBits?
Get it here: www.networkip.net/tidbits
"Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote in
message news:urAKzoNsDHA.2360@.TK2MSFTNGP10.phx.gbl...
> I think I may have an explanation:
> I think that my code: Session("LoginID").ToString breaks if "LoginID" is
not
> in the HttpContext.Current.Session.Keys collection because there is no
> object to call .ToString against.
> Does this sound like a fair explanation? If so, how does one code
> defensively around this issue without writing copious amounts of spag code
> to handle session variables instances not being present?
> Regards,
> Greg Linwood
> SQL Server MVP
> "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote in
> message news:uscsIZNsDHA.560@.TK2MSFTNGP11.phx.gbl...
> > hmm - that's what I did..
> > Perhaps I'm stuffing something up in my config or somewhere else in my
> > code.. I'll keep on debugging & try to identify whatever.. :c/
> > Regards,
> > Greg Linwood
> > SQL Server MVP
> > "Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com> wrote
in
> > message news:#n#vhfMsDHA.1996@.TK2MSFTNGP09.phx.gbl...
> > > Try server.transfer(page.aspx, true).
> > > Are you transferring to a page hosted in the application directory?
That
> > > should work otherwise the problem lies elsewhere.
> > > > regards
> > > > --
> > > > > ----
> > > Got TidBits?
> > > Get it here: www.networkip.net/tidbits
> > > "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote
> in
> > > message news:efMJYVMsDHA.640@.tk2msftngp13.phx.gbl...
> > > > Thanks Alvin - but that didn't work.
> > > > > > I changed my Response.Redirect to a Server.Transfer(page, True) and
I
> > > still
> > > > get the same error...
> > > > > > I noticed that the bPreserveForm argument seems only to apply to
> > > QueryString
> > > > & Form state. I want to preserve variable values in Session state,
> > > similarly
> > > > to the manner in which ASP Session worked. Is this possible in
> ASP.Net?
> > > > Perhaps there's simply some setting I'm not getting right or
> something..
> > > > > > Regards,
> > > > Greg Linwood
> > > > SQL Server MVP
> > > > > > "Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com>
wrote
> > in
> > > > message news:ePvc9KMsDHA.2304@.tk2msftngp13.phx.gbl...
> > > > > when you transfer to another page, it isn't gauranteed to occur on
> the
> > > > same
> > > > > calling thread so all your state information, including session is
> > > > discarded
> > > > > and a new session built up to service the transfer call. If you
want
> > to
> > > > > return state, there is an overloaded function parameter which
> enables
> > > you
> > > > to
> > > > > do so. Server.Transfer(page, bPreserveForm) set this to true and
you
> > > will
> > > > be
> > > > > alright. the default is false. Same deal for redirect.
> > > > > > > > regards
> > > > > > > > --
> > > > > > > > > > > ----
> > > > > Got TidBits?
> > > > > Get it here: www.networkip.net/tidbits
> > > > > "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com>
> wrote
> > > in
> > > > > message news:OcFr9EMsDHA.1884@.TK2MSFTNGP10.phx.gbl...
> > > > > > 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
> > > > > > > > > > > > > > > > > > > >
Thanks Alvin.

I wasn't aware that you needed to do if(Session("login_id") != null) blah
blah blah, which I guess is a new thing you have to do in a strongly typed
environment. It makes sense, because I was testing
Session("login_id").Length which would give an object instance error if the
session variable wasn't there in the first place. Previously, in ASP, you
could check Len(Session("login_id")) which would be fine as any Variant had
a length. It's just a fundamental thinig I was missing. Because I didn't
realise this, I was not being overly careful how I populated the Session
variable in the first place, which was ultimately the source of the
problem - I had an XPATH query which was wrong & caused the
Session("loginid") variable to not be populated first..

Thanks for your help though!

Regards,
Greg Linwood
SQL Server MVP

"Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com> wrote in
message news:uAcvTkRsDHA.3468@.TK2MSFTNGP11.phx.gbl...
> It will break with a null reference exception if login_id isn't there like
> you said. Before touching session variables you should always test:
> if(Session("login_id") != null) blah blah blah. But that doesn't explain
why
> it isn't there after the transfer in the first place. I've written a small
> demo with a transfer and redirect. No matter how you transfer, session
> variables will still be around unless you explicitly clear them. Are you
> clearing it somewhere after the transfer? Otherwise, you will need to
> examine your IIS settings adjusting the recycle properties as needed.
> One more thing you can try is to put code in you session end event to
> populate a static variable. Then try to read this variable on the page you
> transferred to. Session end should never be called under these
> circumstances, otherwise it is the reason for your lost session variables.
> Regards
> --
>
> ----
> Got TidBits?
> Get it here: www.networkip.net/tidbits
> "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote in
> message news:urAKzoNsDHA.2360@.TK2MSFTNGP10.phx.gbl...
> > I think I may have an explanation:
> > I think that my code: Session("LoginID").ToString breaks if "LoginID" is
> not
> > in the HttpContext.Current.Session.Keys collection because there is no
> > object to call .ToString against.
> > Does this sound like a fair explanation? If so, how does one code
> > defensively around this issue without writing copious amounts of spag
code
> > to handle session variables instances not being present?
> > Regards,
> > Greg Linwood
> > SQL Server MVP
> > "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote
in
> > message news:uscsIZNsDHA.560@.TK2MSFTNGP11.phx.gbl...
> > > hmm - that's what I did..
> > > > Perhaps I'm stuffing something up in my config or somewhere else in my
> > > code.. I'll keep on debugging & try to identify whatever.. :c/
> > > > Regards,
> > > Greg Linwood
> > > SQL Server MVP
> > > > "Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com> wrote
> in
> > > message news:#n#vhfMsDHA.1996@.TK2MSFTNGP09.phx.gbl...
> > > > Try server.transfer(page.aspx, true).
> > > > Are you transferring to a page hosted in the application directory?
> That
> > > > should work otherwise the problem lies elsewhere.
> > > > > > regards
> > > > > > --
> > > > > > > > ----
> > > > Got TidBits?
> > > > Get it here: www.networkip.net/tidbits
> > > > "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com>
wrote
> > in
> > > > message news:efMJYVMsDHA.640@.tk2msftngp13.phx.gbl...
> > > > > Thanks Alvin - but that didn't work.
> > > > > > > > I changed my Response.Redirect to a Server.Transfer(page, True)
and
> I
> > > > still
> > > > > get the same error...
> > > > > > > > I noticed that the bPreserveForm argument seems only to apply to
> > > > QueryString
> > > > > & Form state. I want to preserve variable values in Session state,
> > > > similarly
> > > > > to the manner in which ASP Session worked. Is this possible in
> > ASP.Net?
> > > > > Perhaps there's simply some setting I'm not getting right or
> > something..
> > > > > > > > Regards,
> > > > > Greg Linwood
> > > > > SQL Server MVP
> > > > > > > > "Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com>
> wrote
> > > in
> > > > > message news:ePvc9KMsDHA.2304@.tk2msftngp13.phx.gbl...
> > > > > > when you transfer to another page, it isn't gauranteed to occur
on
> > the
> > > > > same
> > > > > > calling thread so all your state information, including session
is
> > > > > discarded
> > > > > > and a new session built up to service the transfer call. If you
> want
> > > to
> > > > > > return state, there is an overloaded function parameter which
> > enables
> > > > you
> > > > > to
> > > > > > do so. Server.Transfer(page, bPreserveForm) set this to true and
> you
> > > > will
> > > > > be
> > > > > > alright. the default is false. Same deal for redirect.
> > > > > > > > > > regards
> > > > > > > > > > --
> > > > > > > > > > > > > > ----
> > > > > > Got TidBits?
> > > > > > Get it here: www.networkip.net/tidbits
> > > > > > "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com>
> > wrote
> > > > in
> > > > > > message news:OcFr9EMsDHA.1884@.TK2MSFTNGP10.phx.gbl...
> > > > > > > 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
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Hi William

I worked this out eventually - it was a Session variable population problem
& a fundamental mis-understanding about a strongly typed issue (which wasn't
a problem in ASP). My other post goes into a little further detail.

Thanks for your response though - my web.config is configured the same as
yours, but this isn't the problem after all.

Regards,
Greg Linwood
SQL Server MVP

"William LaMartin" <lamartin@.tampabay.rr.com> wrote in message
news:#R9b8JRsDHA.2408@.tk2msftngp13.phx.gbl...
> I too have been having problems with Session Variables at some
servers--they
> do not persist after, say, 20 seconds. But your problem is different.
> And your code produces no problem when tested on my computer--the session
> variable displays fine after a server.transfer or response.redirect.
> What do you have in your web.config file as regards session state. Here
is
> what I have (watch word wrap).
> <sessionState
> mode="InProc"
> stateConnectionString="tcpip=127.0.0.1:42424"
> sqlConnectionString="data source=127.0.0.1;user
id=sa;password="
> cookieless="false"
> timeout="60"
> />
> What is this "nasty error" you are receiving?
>
> "Greg Linwood" <g_linwoodremovethisbeforeemailingme@.hotmail.com> wrote in
> message news:OcFr9EMsDHA.1884@.TK2MSFTNGP10.phx.gbl...
> > 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

troubleshooting markup SQLDataSource with a bunch of session variables?

I've got a page with Formview that has a sqldatasource doing a
compicated select with a bunch of session parameter variables set in a
calling page.
1. Is there anyway to response.write all session variables without
having to specify each one?
2. How can I see the actual SQL that is being passed to the Formview?
I've tried
response.write(ChargeDataSource.SelectCommand.ToString()) but that just
what I set originally.
Thanks.For (1):
foreach (string o in Session.Keys)
{
Response.Write (o + ": " + Session[o] + "<br/>");
}
"jobs" <jobs@.webdos.com> wrote in message
news:1161382144.231799.326450@.b28g2000cwb.googlegroups.com...
I've got a page with Formview that has a sqldatasource doing a
compicated select with a bunch of session parameter variables set in a
calling page.
1. Is there anyway to response.write all session variables without
having to specify each one?
2. How can I see the actual SQL that is being passed to the Formview?
I've tried
response.write(ChargeDataSource.SelectCommand.ToString()) but that just
what I set originally.
Thanks.

troubleshooting markup SQLDataSource with a bunch of session variables?

I've got a page with Formview that has a sqldatasource doing a
compicated select with a bunch of session parameter variables set in a
calling page.

1. Is there anyway to response.write all session variables without
having to specify each one?
2. How can I see the actual SQL that is being passed to the Formview?
I've tried
response.write(ChargeDataSource.SelectCommand.ToSt ring()) but that just
what I set originally.

Thanks.For (1):
foreach (string o in Session.Keys)
{
Response.Write (o + ": " + Session[o] + "<br/>");
}

"jobs" <jobs@.webdos.comwrote in message
news:1161382144.231799.326450@.b28g2000cwb.googlegr oups.com...
I've got a page with Formview that has a sqldatasource doing a
compicated select with a bunch of session parameter variables set in a
calling page.

1. Is there anyway to response.write all session variables without
having to specify each one?
2. How can I see the actual SQL that is being passed to the Formview?
I've tried
response.write(ChargeDataSource.SelectCommand.ToSt ring()) but that just
what I set originally.

Thanks.