473,382 Members | 1,648 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,382 software developers and data experts.

SQLSession vs InProcess Session State object references problem (C#)

Hello!

I have a problem with SQLSession state on my ASP.NET pages.

SQLSession state behaves very different from InProcess session state,
which I think is very bad.

I can understand some of the differences, e.g that every object you
store in SQLSession state have to be serializable, but other
differences are very unfortunate.

Look at the following Example:
// Page_Load
....
if(!IsPostBack)
{
Session["A"] = "A";
Session["B"] = Session["A"];
bool aEqualsB = Session["A"] == Session["B"];
return; //Just to place a breakpoint
}
***
in Page_Load, aEqualsB == true in both SQLSession State and InProcess
Session State

but
// In button eventhandler
....
bool aEqualsBAfterPostback = Session["A"] == Session["B"];
return; //Just to place a breakpoint
***
in a Button_Click eventhandler after a postback, aEqualsBAfterPostback
== false
if you use SQLSession State and true if you use InProcess State.

This is really bad!

I have an application where I wan't to isolate the state for every
page, and not overwrite state used by different pages by accident.

I use a framework similar to the User Interface Process (published on
Microsoft Pattern and Practices web site), which allow me to pass
objects between controllers. Each Page has a controller associated to
it, and State is stored in the controller.

Sometimes you DO want to pass state between controllers WITHOUT using
state properties public to the entire application.

This works flawless when using InProcess Session State, but works VERY
bad using SQLSession State.

This results in stupid behavior when users use the back button
functionality, when for example switching between a OrderList and
OrderDetails page, since changing something on the OrderDetails page
doesn't show on the OrderList page, when using the back button. (Using
InProcess State everything works)

Since my application has thousands of users I have to prepare for a
"worst case scenario" where InProcess state isn't enough.

My questions are:
1. Is Microsoft aware of this problem (probably)?
2. Is the behavior acceptable/desirable (probably not)?
3. Is there a good workaround to the problem?

Any help/input appreciated
/ Johan Nedin
Nov 19 '05 #1
1 2382
Johan Nedin wrote:
Hello!

I have a problem with SQLSession state on my ASP.NET pages.

SQLSession state behaves very different from InProcess session state,
which I think is very bad.

I can understand some of the differences, e.g that every object you
store in SQLSession state have to be serializable, but other
differences are very unfortunate.

Look at the following Example:
// Page_Load
...
if(!IsPostBack)
{
Session["A"] = "A";
Session["B"] = Session["A"];
bool aEqualsB = Session["A"] == Session["B"];
return; //Just to place a breakpoint
}
***
in Page_Load, aEqualsB == true in both SQLSession State and InProcess
Session State

but
// In button eventhandler
...
bool aEqualsBAfterPostback = Session["A"] == Session["B"];
return; //Just to place a breakpoint
***
in a Button_Click eventhandler after a postback, aEqualsBAfterPostback
== false
if you use SQLSession State and true if you use InProcess State.

This is really bad!

I have an application where I wan't to isolate the state for every
page, and not overwrite state used by different pages by accident.

I use a framework similar to the User Interface Process (published on
Microsoft Pattern and Practices web site), which allow me to pass
objects between controllers. Each Page has a controller associated to
it, and State is stored in the controller.

Sometimes you DO want to pass state between controllers WITHOUT using
state properties public to the entire application.

This works flawless when using InProcess Session State, but works VERY
bad using SQLSession State.

This results in stupid behavior when users use the back button
functionality, when for example switching between a OrderList and
OrderDetails page, since changing something on the OrderDetails page
doesn't show on the OrderList page, when using the back button. (Using
InProcess State everything works)

Since my application has thousands of users I have to prepare for a
"worst case scenario" where InProcess state isn't enough.

My questions are:
1. Is Microsoft aware of this problem (probably)?
2. Is the behavior acceptable/desirable (probably not)?
3. Is there a good workaround to the problem?

Any help/input appreciated
/ Johan Nedin


What I think happens is this:

with Session["B"] = Session["A"]; both A and B use the *same* reference.
If you immediately check Session["B"] == Session["A"] then you will get a
"true" result, as this "==" checks for equality of *reference* (as Session["whatever"]
returns an object, not what it really was).

With inproc store there will be no change, as everything remains in memory.
With external session state (StateServer, SqlServer), then both Session["A"]
and Session["B"] will get serialized. When you refer to A or B again, they are
retrieved from the session store. The values are still the same, but now
they are independant objects (separate references), so an equality check
(on those *references*) will return false!

One solution would be not to check references, but to check values, as in:
(string)Session["A"] == (string)Session["B"]
As you are now comparing *values* (of course both need to be strings
for this exact code to work) the result will be what you want.

Hans Kesting

Nov 19 '05 #2

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

Similar topics

2
by: adam | last post by:
Having spent nearly 2 years in win forms land the inevitable request came for me to "do some web pages". So being new to this bit of .net and having had a look around I can't see where the best...
2
by: martin | last post by:
Hi, I am just about to deploy my production application on a win2k server with two processors. I have been reading that inprocess session state is not the best method for multi processor...
7
by: Seth | last post by:
I have noticed that the id of my session object changes when I switch from a non-secure to a secure connection. What I'm trying to do: I have a cookie that is built on the non-secure side of...
1
by: mirek | last post by:
Hi, I'd like to know how session variables are stored in the session. I if put a object to the session and then get it back, is this the same object or a new copy of it? The session holds...
5
by: ASP.Confused | last post by:
As you can tell from my previous posts on this issue...I'm really confused :-/ I have a few ASP.NET web applications on my web host's "https" server. Our web host has a single "bin" folder for...
5
by: fbwhite | last post by:
I know this issue has been brought up many times, but I have tried many of the solutions to no avail. I wanted to give my specific case to see if someone could be of any help. We are using the...
13
by: | last post by:
Simple question, I think... I'm storing an object in the Session object. In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction) If I change any...
3
by: codegreen9 | last post by:
Hi, My understanding is that session info must be stored using Session, which means text data. What I'd like to be able to do, is keep an object alive throughout a user's session, without...
6
by: Bhagya | last post by:
Hello, On the LogOut Page i have done Session.Abandon(); And on every Page, In the Page_Load Event i check if the session exists and only then display data. Now the problem is after i logout from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.