473,734 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Putting a class in a Session

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.ToStrin g in it!!

Thanks,
Alan
Nov 18 '05 #1
5 1196
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*******@sapm 123.com> wrote in message
news:eu******** ******@tk2msftn gp13.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.ToStrin g in it!!

Thanks,
Alan

Nov 18 '05 #2
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.c c> wrote in message
news:Ov******** ********@TK2MSF TNGP09.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*******@sapm 123.com> wrote in message
news:eu******** ******@tk2msftn gp13.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.ToStrin g in it!!

Thanks,
Alan


Nov 18 '05 #3
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*******@sapm 123.com> wrote in message
news:Ol******** ******@TK2MSFTN GP09.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.c c> wrote in message
news:Ov******** ********@TK2MSF TNGP09.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*******@sapm 123.com> wrote in message
news:eu******** ******@tk2msftn gp13.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.ToStrin g in it!!

Thanks,
Alan



Nov 18 '05 #4
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*********@kp mg.com> wrote in message
news:Oo******** ******@TK2MSFTN GP12.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*******@sapm 123.com> wrote in message
news:Ol******** ******@TK2MSFTN GP09.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.c c> wrote in message
news:Ov******** ********@TK2MSF TNGP09.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*******@sapm 123.com> wrote in message
news:eu******** ******@tk2msftn gp13.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.ToStrin g in it!!
>
> Thanks,
> Alan
>
>



Nov 18 '05 #5
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7247
by: Colin Steadman | last post by:
I'm trying to create a VBScript using ASP. However I'm having problems getting data from session variables into the right places. The example I have copied below works, however I need to replace "data1" and "data2" with real data from a session variable. However if I replace this: Call OpenDoc("data1", "data2") With this:
12
2877
by: James Norton-Jones | last post by:
Hi, Am I trying to hold the data of a DataGrid in a label so that when the form is reposted the DataGrid can be repopulated. The problem I am having is that I don't understand how to get the text into a stream in order to be able to use DataSetOutcomes1.ReadXML(MyStream). Thanks in advance, James
5
2097
by: Makarand | last post by:
Hi Friends I have collection class implementing from IList. Problem I am facing is I am not able to put this object in ViewState(though it is going in Session). When I try to do this it gives error like -- "The type 'IListStuff.PersonCollection' must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate"
2
2291
by: John Mullin | last post by:
We are having a problem which appears similar to a previous posting: http://groups.google.com/groups?hl=en&lr=&frame=right&th=d97f552e10f8c94c&seekm=OZw33z9EDHA.2312%40TK2MSFTNGP10.phx.gbl#link1 In the current release of our system, we decided to "wrap" the ASP.NET Session and Application objects to improve code clarity and accuracy. For example, instead of: Session = new SomeListClass;
2
1606
by: Chris Puncher | last post by:
Hi. I have a RCW class that was generated by the VS.NET2003 IDE when I added a COM dll reference to my project. This all works fine when I call methods on it. My initial problem is that in ASP.NET I would like to add this to the Session object whilst using SQLServer as the session storage. Unfortunately, as this required the RCW class to be serializable, this won't work, and throws an exception saying you can't Serialize the Session...
15
2417
by: Joe Fallon | last post by:
I would like to know how you can figure out how much memory a given instance of a class is using. For example, if I load a collection class with 10 items it might use 1KB, and if I load it with 1000 items it might use 100KB. How do I measure the amount of memory used once the class is loaded? Thanks! -- Joe Fallon
5
1972
by: Steven Blair | last post by:
I have the following code: Session = new CurrentUser("TEST"); When I postback to the server, the Session is null. My guess is a only the refence to my actual class is stored, rather than the class. Looking on the internet, one solution posted was populating Session in Session_Start in a global.asax file. Again, on postback, the value is
1
1348
by: nem.usenet | last post by:
Hi everyone, I searched for this but with little luck. I'm working on a project and need to do the following: 1. have a user authenticate to an ASP.net site using windows authentication 2. take either HttpContext.User or HttpContext.Current.User as the parameter for a stored procedure that will draw some simple data on that user. 3. put those bits of data into session (just a handful of fields,
4
3144
by: Mike P | last post by:
I have created my own generic class that I need to persist across postbacks. Here is my code : private void AgentSelector() { List<AgentagentList = new List<Agent>(); CheckBox chk; int a = 0;
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.