Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > asp.net serializing

Reply
Thread Tools

asp.net serializing

 
 
venky
Guest
Posts: n/a
 
      01-12-2005
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

 
Reply With Quote
 
 
 
 
Shimon Sim
Guest
Posts: n/a
 
      01-12-2005
Check Session object of the Page class.
It should be a good place to start.
Shimon
www.siatadev.com

"venky" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...
>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
>



 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?=22Anders_Nor=E5s_=5BMCAD=5D=22?=
Guest
Posts: n/a
 
      01-12-2005
venky wrote:
> 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/
 
Reply With Quote
 
venkat chellam
Guest
Posts: n/a
 
      01-13-2005


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
=?ISO-8859-1?Q?=22Anders_Nor=E5s_=5BMCAD=5D=22?=
Guest
Posts: n/a
 
      01-13-2005
venkat chellam wrote:
> 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/de...sp12282000.asp

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Serializing an object from HttpApplicationState Natan ASP .Net 5 09-27-2004 10:53 AM
Serializing classes from Web Services Russ ASP .Net 1 08-10-2004 01:33 PM
problem de-serializing a dataset MattB ASP .Net 0 04-27-2004 05:47 PM
serializing a class & performance -- advice? Jason Shohet ASP .Net 4 07-29-2003 06:47 PM
Serializing classes derived from dataset Aidan Glendye ASP .Net 1 07-28-2003 02:29 PM



Advertisments