473,395 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Some basic session state questions

Hi,

My understanding is that session info must be stored using
Session["var"], which means text data. What I'd like to be able to do,
is keep an object alive throughout a user's session, without having to
serialize my data into text, save it as Session["var"], and restore it
using Session["var"] every time the user moves to a different page.

Is there no way to have a session *object* stay in memory and preserve
variable state without serialize/deserialize/Session[] ?

Also, depending on what a user is doing, I'd like to temporarily store
his/her selections in SQL, for the duration of the session, then wipe
out that temporary data when the session expires. Is there a way I can
use the .net framework to do that? By notifying me or a SQL stored
procedure to clean out that data? I could use a scheduled stored proc
to wipe out old temp data, I just wondered if there's anything in
ASP.NET that I could tap into.

Thanks in advance

Apr 10 '06 #1
3 1536
> Hi,

My understanding is that session info must be stored using
Session["var"], which means text data. What I'd like to be able to do,
is keep an object alive throughout a user's session, without having to
serialize my data into text, save it as Session["var"], and restore it
using Session["var"] every time the user moves to a different page.

Is there no way to have a session *object* stay in memory and preserve
variable state without serialize/deserialize/Session[] ?
Thanks in advance


In Session you store *objects* (or rather: *references* to objects),
not just strings. So you can store any object there without
(de)serialization. That is, if you use "InProc" sessions. When you use
StateServer or SqlServer to store session data, then the object needs
to be serializable, but you don't have to do it yourself.
When you retrieve the object from Session, you have to cast is to the
correct type.

MyObject obj = new MyObject();
Session["mine"] = obj;
....
MyObject obj2 = (MyObject)Session["mine"];
By the way, there is also a microsoft.public.dotnet.framework.aspnet
newsgroup...
Hans Kesting
Apr 10 '06 #2
Do u really need SQL for this? Why not to use just Cache, or StateServer?
SQL/StateServer are aimed to keep you data permanently.

BTW, if you want to clear your tables in case of session end call you SQL
script in the Session_End handler in global.aspx
Also, depending on what a user is doing, I'd like to temporarily store
his/her selections in SQL, for the duration of the session, then wipe
out that temporary data when the session expires. Is there a way I can
use the .net framework to do that? By notifying me or a SQL stored
procedure to clean out that data? I could use a scheduled stored proc
to wipe out old temp data, I just wondered if there's anything in
ASP.NET that I could tap into.


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Apr 10 '06 #3
Thanks very much for the replies.

Hans: Thanks for the info. Also, the .aspnet group would have been
more appropriate, thanks for mentioning it. Is it a common (or
advisable) practice to save and restore the Page object itself
(InProc)?

Michael: Thanks for pointing out Session_End. For this project, I have
a reason to use SQL other than simply as a mechanism for storing
session info. The reason for storing info in SQL would be to set up
another stored procedure call that I'll need to do. This boils down to
a "best practices" SQL question. The user will be able to select 1-600
items, which translate into rows in table A. So, I think the "best
practice" option would be to bulk insert the selections into another
SQL table (table B), and use a join to pull out the data from table A,
which could be done with a single stored procedure call. Then I'd need
to clean out table B.

Other options would be making a stored procedure call for every
selection (up to 600, not very efficient), or passing the selections as
an array and parsing (not very relational).

After writing this post, I think I'll end up pulling all rows from
table A once, at the application level (the data is pretty static), and
use DataViews at the session level to let users pick and choose their
data. One SQL stored proc call per day... yeah, i like that better...
:)

Apr 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: grw | last post by:
Im trying to find why my hosted server won't maintain session state. Its not a web farm (not load balanced), its all the same server An application requires a session to be set and then recalled...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
8
by: Anthony P. Mancini | last post by:
I'm working on a proof of concept that will ultimately be deployed on a load balancer. For the sake of a preliminary demonstration I created a C# object and marked it's attributes as Public...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
3
by: ESmith | last post by:
I have multi-page form where I pass an object between pages as follows: On each page: // What page to go to next private void btnContinue_Click(object sender, System.EventArgs e) { if...
3
by: Ken Varn | last post by:
In looking into Web Services, I noticed that they can maintain Session variables. How does a web service distinguish different sessions? Does this occur when the client creates an instance of the...
3
by: James Simpson | last post by:
Hello, I am currently deploying an ASP .NET based web application via Visual Studio 2005 (so I am using .NET 2.0 technology). The two questions I have are with regards to session state in...
2
by: weird0 | last post by:
Hi! I need answers to these questions that were given to me in a job test. 1. What is IDisposable in .NET? 2.What is the base class of all the controls in .NET? 3.What is the difference...
2
by: Ian Semmel | last post by:
I am new to this world of ASP.NET so forgive the dumb questions. I have been looking at the sample provided 'Implementing a Session-State Store Provider' in an effort to understand how the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...

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.