asp.net serializing

V

venky

I am new to asp.net and web programming. A question regarding the
state management.


I query a database and store a record in the class object. Now i want
to store this object on postbacks. whats the best way?
If anyone can throw more light on serilzing, it would be great help
 
?

=?ISO-8859-1?Q?=22Anders_Nor=E5s_=5BMCAD=5D=22?=

venky said:
I query a database and store a record in the class object. Now i want
to store this object on postbacks. whats the best way?
The easiest way to persist an object between postbacks is to store it in
the the Session object. You have three different storage locations for
the session data:
1. InProc - session kept as live objects in web server (aspnet_wp.exe).
This is the default setting.
2. StateServer - session serialized and stored in memory in a separate
process (aspnet_state.exe). State Server can run on another machine
3. SQLServer - session serialized and stored in SQL server

The storeage location is configured in the web.config file.

You can also store objects in the page view state. When you to this the
object(s) are serialized, base64 encoded and included as a hidden text
field in the HTML output. This field is posted back to the server where
the object(s) are rehydrated.
If anyone can throw more light on serilzing, it would be great help
You can serialize an object with the classes in
System.Runtime.Serialization or System.Xml.Serialization. To serialize
an object (myObject) with System.Xml.Serialization.BinaryFormatter, you
can do the following (C#):

MyClass myObject=new MyClass();
MemoryStream stream=new MemoryStream();
BinaryFormatter formatter=new BinaryFormatter();
formatter.Serialize(stream, myObject);

To deserialize the stream to an MyClass instance, you can do this (C#):
MyClasss myDeserializedObject=(MyClass) formatter.Deserialize(stream);

To serialize an object with the System.Xml.Serialization.XmlSerializer
class do this:

MyClass myObject=new MyClass();
XmlSerializer serializer=new XmlSerializer(typeof (MyClass));
MemoryStream stream=new MemoryStream();
XmlTextWriter writer=new XmlTextWriter(stream, Encoding.Unicode);
serializer.Serialize(writer, myObject);

To deserialize the stream to a MyClass instance, do this:
MyClasss myDeserializedObject=(MyClass) serializer.Deserialize(stream);

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
V

venkat chellam

Thanks for replying.

If i decide to use session object, do i have to handle session timeout?
What if i don't want to have timeout and even if the user keeps his
browser open and comes next day and should be able to continue from
where u left previously?
how do i handle this?

venky
 
?

=?ISO-8859-1?Q?=22Anders_Nor=E5s_=5BMCAD=5D=22?=

venkat said:
If i decide to use session object, do i have to handle session timeout?
What if i don't want to have timeout and even if the user keeps his
browser open and comes next day and should be able to continue from
where u left previously?
how do i handle this?
The session configuration element in web.config has a timeout attribute
which controls how long a session is concidered valid. The session
timeout is a sliding value; on each request the timeout period is set to
the current time plus the timeout value.
If you need the session to be valid "forever", like session at
Amazon.com or similar, you should use SQL Server Mode.

For good coverage of session state in ASP.NET read Rob Howards MSDN
article on the topic
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp12282000.asp

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top