By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

Putting a class in a Session

P: n/a
A.M
Hi,

How can I store a class (including all it's members) in session object?

I already tried something like:

Session["Status"] = myClass;

but it stores the value of myClass.ToString in it!!

Thanks,
Alan
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
The Session object is a collection of -objects-. Any objects, but to
properly use the class after retrieving from the Session, you must cast it
back from an object to its native type:
myClass = (MyType)Session["Status"]; I'm not 100% sure that this is the
problem that you are having, but that is how I use Session to store an
object.

I use Session all the time to store complete objects. It works great.

Jeffrey Palermo

"A.M" <IH*******@sapm123.com> wrote in message
news:eu**************@tk2msftngp13.phx.gbl...
Hi,

How can I store a class (including all it's members) in session object?

I already tried something like:

Session["Status"] = myClass;

but it stores the value of myClass.ToString in it!!

Thanks,
Alan

Nov 18 '05 #2

P: n/a
A.M

Than you for help.

The Trace is on for all pages.
How can I see the members of that object in Trace output? Because Trace just
shows the class name (like myClass)!!.

Thanks again,
Alan

"Jeffrey Palermo" <Je*****************@Palermo.cc> wrote in message
news:Ov****************@TK2MSFTNGP09.phx.gbl...
The Session object is a collection of -objects-. Any objects, but to
properly use the class after retrieving from the Session, you must cast it
back from an object to its native type:
myClass = (MyType)Session["Status"]; I'm not 100% sure that this is the
problem that you are having, but that is how I use Session to store an
object.

I use Session all the time to store complete objects. It works great.

Jeffrey Palermo

"A.M" <IH*******@sapm123.com> wrote in message
news:eu**************@tk2msftngp13.phx.gbl...
Hi,

How can I store a class (including all it's members) in session object?

I already tried something like:

Session["Status"] = myClass;

but it stores the value of myClass.ToString in it!!

Thanks,
Alan


Nov 18 '05 #3

P: n/a
You will need to override the .ToString() method for your class. I believe
the trace calls .ToString() on each object in Session, etc.

bill

"A.M" <IH*******@sapm123.com> wrote in message
news:Ol**************@TK2MSFTNGP09.phx.gbl...

Than you for help.

The Trace is on for all pages.
How can I see the members of that object in Trace output? Because Trace just shows the class name (like myClass)!!.

Thanks again,
Alan

"Jeffrey Palermo" <Je*****************@Palermo.cc> wrote in message
news:Ov****************@TK2MSFTNGP09.phx.gbl...
The Session object is a collection of -objects-. Any objects, but to
properly use the class after retrieving from the Session, you must cast it back from an object to its native type:
myClass = (MyType)Session["Status"]; I'm not 100% sure that this is the
problem that you are having, but that is how I use Session to store an
object.

I use Session all the time to store complete objects. It works great.

Jeffrey Palermo

"A.M" <IH*******@sapm123.com> wrote in message
news:eu**************@tk2msftngp13.phx.gbl...
Hi,

How can I store a class (including all it's members) in session object?
I already tried something like:

Session["Status"] = myClass;

but it stores the value of myClass.ToString in it!!

Thanks,
Alan



Nov 18 '05 #4

P: n/a
Yes, that's right. Session stores objects, not just strings, and if you
don't explicitly define a ToString() method, then the one inherited from
Ojbect will be called, and that's not what you want, so override ToString()
and have it return some key information in your object.

Jeffrey Palermo

"William F. Robertson, Jr." <wf*********@kpmg.com> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl...
You will need to override the .ToString() method for your class. I believe the trace calls .ToString() on each object in Session, etc.

bill

"A.M" <IH*******@sapm123.com> wrote in message
news:Ol**************@TK2MSFTNGP09.phx.gbl...

Than you for help.

The Trace is on for all pages.
How can I see the members of that object in Trace output? Because Trace just
shows the class name (like myClass)!!.

Thanks again,
Alan

"Jeffrey Palermo" <Je*****************@Palermo.cc> wrote in message
news:Ov****************@TK2MSFTNGP09.phx.gbl...
The Session object is a collection of -objects-. Any objects, but to
properly use the class after retrieving from the Session, you must cast it
back from an object to its native type:
myClass = (MyType)Session["Status"]; I'm not 100% sure that this is
the problem that you are having, but that is how I use Session to store an
object.

I use Session all the time to store complete objects. It works great.

Jeffrey Palermo

"A.M" <IH*******@sapm123.com> wrote in message
news:eu**************@tk2msftngp13.phx.gbl...
> Hi,
>
> How can I store a class (including all it's members) in session

object? >
> I already tried something like:
>
> Session["Status"] = myClass;
>
> but it stores the value of myClass.ToString in it!!
>
> Thanks,
> Alan
>
>



Nov 18 '05 #5

P: n/a
Hi Alan,

I've found that there is anothe thread named
"Re: Putting a class in a Session" in the same newsgroup on this issue and
some community member also provide some informative suggestions there. I'd
appreciate if you have a look there. Also, if you feel convenient that we
continue to discuss in that thread, please feel free to followup there.
Thanks.

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

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.