473,698 Members | 2,360 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 1193
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
7240
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
2874
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
2095
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
2288
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
1603
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
2416
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
1968
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
1346
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
3143
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
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9166
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8899
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
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7737
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
6525
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
5861
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
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2007
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.