Using the Session object

G

Guest

Simple question, I think...

I'm storing an object in the Session object.

In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction)

If I change any properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object?

Thanks,
Jerry
 
E

Eliyahu Goldin

Jerry,

You are right, you have to update session variables, there is no automatic link.

Eliyahu

Simple question, I think...

I'm storing an object in the Session object.

In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction)

If I change any properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object?

Thanks,
Jerry
 
K

Karl Seguin [MVP]

They are all references to the same space in the heap (memory). When you assign it to a new variable, you are only getting a handle on that space in memory.

So both your guesses are wrong. You don't have to store it back in the session, but that isn't because it's automatically "saved back into the session object".

Rather, the reason you don't have to save it back into the session is because there's ever only 1 instance of this object (unless you clone it) and thus updates made by any variable that point to that location will be reflected in all other variables that point there also.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


Simple question, I think...

I'm storing an object in the Session object.

In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction)

If I change any properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object?

Thanks,
Jerry
 
K

Karl Seguin [MVP]

one of us is fundamentally wrong...

loading up a test..

Jerry,

You are right, you have to update session variables, there is no automatic link.

Eliyahu

Simple question, I think...

I'm storing an object in the Session object.

In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction)

If I change any properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object?

Thanks,
Jerry
 
P

Peter Rilling

Doesn't the concept of "references" form an automatic link. If he modifies the variable "trx", then that would also be reflected back in the session version, right? Unless the value stored in the session is a value type.

Jerry,

You are right, you have to update session variables, there is no automatic link.

Eliyahu

Simple question, I think...

I'm storing an object in the Session object.

In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction)

If I change any properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object?

Thanks,
Jerry
 
K

Karl Seguin [MVP]

That's what I said, and I just tried it out to make sure I wasn't bonkers.

I'm not familiar with BOCSTransaction so anything's possible, but I think Peter and I are right on this one.

Karl

Doesn't the concept of "references" form an automatic link. If he modifies the variable "trx", then that would also be reflected back in the session version, right? Unless the value stored in the session is a value type.

Jerry,

You are right, you have to update session variables, there is no automatic link.

Eliyahu

Simple question, I think...

I'm storing an object in the Session object.

In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction)

If I change any properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object?

Thanks,
Jerry
 
H

Hans Kesting

That's what I said, and I just tried it out to make sure I wasn't bonkers.
I'm not familiar with BOCSTransaction so anything's possible, but I think
Peter and I are right on this one.

Karl

If "BOCSTransaction" is an object, then this is true (just the
reference is stored in Session, so you are updating the "real" object).
However (just to be complete), if "BOCSTransaction" is a struct
(ValueType, sorry, don't know the VB name) then you will get a *copy*
of the stored struct. So then you *will* have to "store back" the
changed struct.

Hans Kesting
 
B

Bruce Barker

this is only true if the whats stored is session is an object. if its a value type (int, structure, etc), then you need to replace the session object.

also there are differences depending on the session manager. a inproc session manager hold a reference to the object until replaced or the session expires. an out-proc session manager (state, sqlserver), only references the object during the request, at request end, its serialized out. this means you can reference a session variable between requests (say a background thread) with a inproc session handler but not in out of proc hander. \

aslso if you store the same object twice in the session, if in proc they are the same object and stay the same, but in an out of proc session, they become seperate object on the next request.



-- bruce (sqlwork.com)

They are all references to the same space in the heap (memory). When you assign it to a new variable, you are only getting a handle on that space in memory.

So both your guesses are wrong. You don't have to store it back in the session, but that isn't because it's automatically "saved back into the session object".

Rather, the reason you don't have to save it back into the session is because there's ever only 1 instance of this object (unless you clone it) and thus updates made by any variable that point to that location will be reflected in all other variables that point there also.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


Simple question, I think...

I'm storing an object in the Session object.

In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction)

If I change any properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object?

Thanks,
Jerry
 
G

Guest

Okay... Thanks everyone for their input.

This is my understanding...

BOCSTransaction is my own class, so it's an object stored, apparetly, by reference in the Session and I don't need to update the Session every time I change a property of it.

I'm still kinda new to the web architecture. I just wasn't sure if objects were serialized into some common space when you stored them in the Session. If it is truly just a heap pointer, then it's easy. Thanks.

Jerry

Simple question, I think...

I'm storing an object in the Session object.

In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction)

If I change any properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object?

Thanks,
Jerry
 
S

Steven Cheng[MSFT]

Assume that we're using Inproc session, then all the variables held in
session state are in-memory objects. So whether we can directly modify the
object without reassign it back to the sessionstate entry depend on its
class type. If it's of reference type, the session state entry just hold
the reference to that object, so we can certainly just update it without
explicitly reassign. If a value type, reassign is necessary....

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.)


--------------------
| Subject: Re: =?UTF-8?B?VXNpbmcgdGhlIFNlc3Npb24gb2JqZWN0?=
| From: "Hans Kesting" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Message-ID: <[email protected]>
| X-Newsreader: MesNews/1.04.01.00-gb
| Date: Mon, 23 Jan 2006 18:03:03 +0100
| MIME-Version: 1.0
| Content-Type: text/plain; charset="utf-8"; format=flowed
| Content-Transfer-Encoding: 8bit
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 127-24.bbned.dsl.internl.net 82.215.24.127
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372924
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| > That's what I said, and I just tried it out to make sure I wasn't
bonkers.
| >
| > I'm not familiar with BOCSTransaction so anything's possible, but I
think
| > Peter and I are right on this one.
| >
| > Karl
|
| If "BOCSTransaction" is an object, then this is true (just the
| reference is stored in Session, so you are updating the "real" object).
| However (just to be complete), if "BOCSTransaction" is a struct
| (ValueType, sorry, don't know the VB name) then you will get a *copy*
| of the stored struct. So then you *will* have to "store back" the
| changed struct.
|
| Hans Kesting
|
|
| >
| > Doesn't the concept of
| > "references" form an automatic link. If he modifies the variable
"trx", then
| > that would also be reflected back in the session version, right?
Unless the
| > value stored in the session is a value type.
| >
| > Jerry,
| >
| > You are right, you have to update session variables, there is no
| > automatic link.
| >
| > Eliyahu
| >
| > Simple question, I
| > think...
| >
| > I'm storing an object in the Session object.
| >
| > In the code behind I read that object: trx =
| > CType(Session("Transaction"), BOCSTransaction)
| >
| > If I change any properties, I have to store it back into the
session
| > object to "update" it, right? Or will the changes to my object
automatically
| > be saved back into the session object?
| >
| > Thanks,
| > Jerry
|
|
|
 
E

Eliyahu Goldin

Steven,

Do you mean that with outproc sessions you have to reassign always? If it is
true, isn't then reassigning is a good practice since you can switch between
different session managements without code changes?

Eliyahu
 
S

Steven Cheng[MSFT]

Of course not, Inproc session is the default and simplest scenario. For
out-proc session, first , class objects(not primitive types) which need to
be stored in session must be serializable, otherwise they can not be stored
in session. So that's another story an d I just use inproc session for
instance...

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.)
--------------------
| From: "Eliyahu Goldin" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<qMso#[email protected]>
| Subject: Re: Using the Session object
| Date: Tue, 24 Jan 2006 09:55:17 +0200
| Lines: 108
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 212.143.94.3
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:373054
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steven,
|
| Do you mean that with outproc sessions you have to reassign always? If it
is
| true, isn't then reassigning is a good practice since you can switch
between
| different session managements without code changes?
|
| Eliyahu
|
|
| | > Assume that we're using Inproc session, then all the variables held in
| > session state are in-memory objects. So whether we can directly modify
the
| > object without reassign it back to the sessionstate entry depend on its
| > class type. If it's of reference type, the session state entry just hold
| > the reference to that object, so we can certainly just update it without
| > explicitly reassign. If a value type, reassign is necessary....
| >
| > 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.)
| >
| >
| > --------------------
| > | Subject: Re: =?UTF-8?B?VXNpbmcgdGhlIFNlc3Npb24gb2JqZWN0?=
| > | From: "Hans Kesting" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > | Message-ID: <[email protected]>
| > | X-Newsreader: MesNews/1.04.01.00-gb
| > | Date: Mon, 23 Jan 2006 18:03:03 +0100
| > | MIME-Version: 1.0
| > | Content-Type: text/plain; charset="utf-8"; format=flowed
| > | Content-Transfer-Encoding: 8bit
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: 127-24.bbned.dsl.internl.net 82.215.24.127
| > | Lines: 1
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:372924
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | > That's what I said, and I just tried it out to make sure I wasn't
| > bonkers.
| > | >
| > | > I'm not familiar with BOCSTransaction so anything's possible, but I
| > think
| > | > Peter and I are right on this one.
| > | >
| > | > Karl
| > |
| > | If "BOCSTransaction" is an object, then this is true (just the
| > | reference is stored in Session, so you are updating the "real"
object).
| > | However (just to be complete), if "BOCSTransaction" is a struct
| > | (ValueType, sorry, don't know the VB name) then you will get a *copy*
| > | of the stored struct. So then you *will* have to "store back" the
| > | changed struct.
| > |
| > | Hans Kesting
| > |
| > |
| > | >
| > | > Doesn't the concept
of
| > | > "references" form an automatic link. If he modifies the variable
| > "trx", then
| > | > that would also be reflected back in the session version, right?
| > Unless the
| > | > value stored in the session is a value type.
| > | >
message
| > | > Jerry,
| > | >
| > | > You are right, you have to update session variables, there is no
| > | > automatic link.
| > | >
| > | > Eliyahu
| > | >
| > | > Simple question,
I
| > | > think...
| > | >
| > | > I'm storing an object in the Session object.
| > | >
| > | > In the code behind I read that object: trx =
| > | > CType(Session("Transaction"), BOCSTransaction)
| > | >
| > | > If I change any properties, I have to store it back into the
| > session
| > | > object to "update" it, right? Or will the changes to my object
| > automatically
| > | > be saved back into the session object?
| > | >
| > | > Thanks,
| > | > Jerry
| > |
| > |
| > |
| >
|
|
|
 
E

Eliyahu Goldin

As you said, the requirement of being serializable is another story, I know
about it. I am asking on reassigning. Do outproc session managers work as
Bruce describes in another post to this thread, that session variables get
serialized out at the end of request, and, therefore, you don't need to
reassign?

Eliyahu
 
S

Steven Cheng[MSFT]

Yes, as for reassigning, it's the same with inproc session.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Eliyahu Goldin" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<qMso#[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Using the Session object
| Date: Tue, 24 Jan 2006 12:31:22 +0200
| Lines: 177
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 212.143.94.3
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:373082
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| As you said, the requirement of being serializable is another story, I
know
| about it. I am asking on reassigning. Do outproc session managers work as
| Bruce describes in another post to this thread, that session variables
get
| serialized out at the end of request, and, therefore, you don't need to
| reassign?
|
| Eliyahu
|
| | > Of course not, Inproc session is the default and simplest scenario. For
| > out-proc session, first , class objects(not primitive types) which need
to
| > be stored in session must be serializable, otherwise they can not be
| > stored
| > in session. So that's another story an d I just use inproc session for
| > instance...
| >
| > 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.)
| > --------------------
| > | From: "Eliyahu Goldin" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <qMso#[email protected]>
| > | Subject: Re: Using the Session object
| > | Date: Tue, 24 Jan 2006 09:55:17 +0200
| > | Lines: 108
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: 212.143.94.3
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:373054
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Steven,
| > |
| > | Do you mean that with outproc sessions you have to reassign always?
If
| > it
| > is
| > | true, isn't then reassigning is a good practice since you can switch
| > between
| > | different session managements without code changes?
| > |
| > | Eliyahu
| > |
| > |
| > | | > | > Assume that we're using Inproc session, then all the variables held
in
| > | > session state are in-memory objects. So whether we can directly
modify
| > the
| > | > object without reassign it back to the sessionstate entry depend on
| > its
| > | > class type. If it's of reference type, the session state entry just
| > hold
| > | > the reference to that object, so we can certainly just update it
| > without
| > | > explicitly reassign. If a value type, reassign is necessary....
| > | >
| > | > 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.)
| > | >
| > | >
| > | > --------------------
| > | > | Subject: Re: =?UTF-8?B?VXNpbmcgdGhlIFNlc3Npb24gb2JqZWN0?=
| > | > | From: "Hans Kesting" <[email protected]>
| > | > | References: <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > | Message-ID: <[email protected]>
| > | > | X-Newsreader: MesNews/1.04.01.00-gb
| > | > | Date: Mon, 23 Jan 2006 18:03:03 +0100
| > | > | MIME-Version: 1.0
| > | > | Content-Type: text/plain; charset="utf-8"; format=flowed
| > | > | Content-Transfer-Encoding: 8bit
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | NNTP-Posting-Host: 127-24.bbned.dsl.internl.net 82.215.24.127
| > | > | Lines: 1
| > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet:372924
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > |
| > | > | > That's what I said, and I just tried it out to make sure I
wasn't
| > | > bonkers.
| > | > | >
| > | > | > I'm not familiar with BOCSTransaction so anything's possible,
but
| > I
| > | > think
| > | > | > Peter and I are right on this one.
| > | > | >
| > | > | > Karl
| > | > |
| > | > | If "BOCSTransaction" is an object, then this is true (just the
| > | > | reference is stored in Session, so you are updating the "real"
| > object).
| > | > | However (just to be complete), if "BOCSTransaction" is a struct
| > | > | (ValueType, sorry, don't know the VB name) then you will get a
| > *copy*
| > | > | of the stored struct. So then you *will* have to "store back" the
| > | > | changed struct.
| > | > |
| > | > | Hans Kesting
| > | > |
| > | > |
| > | > | >
| > | > | > Doesn't the
concept
| > of
| > | > | > "references" form an automatic link. If he modifies the
variable
| > | > "trx", then
| > | > | > that would also be reflected back in the session version, right?
| > | > Unless the
| > | > | > value stored in the session is a value type.
| > | > | >
| > message
| > | > | > Jerry,
| > | > | >
| > | > | > You are right, you have to update session variables, there
is
| > no
| > | > | > automatic link.
| > | > | >
| > | > | > Eliyahu
| > | > | >
| > | > | > Simple
| > question,
| > I
| > | > | > think...
| > | > | >
| > | > | > I'm storing an object in the Session object.
| > | > | >
| > | > | > In the code behind I read that object: trx =
| > | > | > CType(Session("Transaction"), BOCSTransaction)
| > | > | >
| > | > | > If I change any properties, I have to store it back into
the
| > | > session
| > | > | > object to "update" it, right? Or will the changes to my object
| > | > automatically
| > | > | > be saved back into the session object?
| > | > | >
| > | > | > Thanks,
| > | > | > Jerry
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top