By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

Need Microsoft Help: Session object retrieving another user's Session information

P: n/a

I'm building a complex web-based reservations system.

Gathering the user's data requires between 8 and 15 pages (depending on
which options they are interested in). I use the "Session" object to store
the various elements as the user moves through the pages.

Rather than storing the preferences directly in the Session object (e.g.
Session("LastName") = ...), I created a class

<Serializable()> Public Class ReservationInfo

This class has private variables for all the data, and exposes properties to
retrieve/manipulate the data. I did this for several reasons:
* I don't have to worry about screwing up variable names from one page
to the next (is it Session("OptionNumber") or is it Session("OptionNbr")) --
* I can add some logic related to the assignment of properties (e.g. if
a property changes, I might need to reset other properties)
In one of my modules I declare

dim g_Info as ReservationInfo

And on each page, then, in the OnLoad event, I have something to this
effect:
g_Info = Current.Session("ReservationInfo")

(actually, in the OnLoad event I call a public sub in one of my
modules, and it does the retrieval. That's why it references
Current.Session)
and in the Unload event, I have
Session("ReservationInfo") = g_Info
This way my entire set of variables is loaded from the Session, and saved
back to the session each time.

I let .NET manage the Session object in memory (single server), and
everything works great (or at least it did during my development/testing).

The problem happened when we ran the first multi-user test (e.g. 5 people
testing at the same time).

Suddenly, as users moved from page to page, their session information was
getting swapped with the information from another user. Every so often
(every couple of pages or so), as you moved from one page to another, you
suddenly wound up with the data of another user on the system.
I then added logic so that in the unload event, it would serialize and dump
the entire g_Info object to disk, and the filename would be based on the
SessionID of the user. That way I could trace the session information of
each user as they moved from page to page. I've confirmed that this happens
there. It seems that when it retrieves the data from the Session object
g_Info = Current.Session("ReservationInfo")
it sometimes grabs the wrong data.

I've analyzed several hundred page requests, and found many occurrences, but
can't find any pattern to it.
I don't have a clue how this could be. Any ideas?

Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello Boban,
there. It seems that when it retrieves the data from the Session
object
g_Info = Current.Session("ReservationInfo")
it sometimes grabs the wrong data.
I've analyzed several hundred page requests, and found many
occurrences, but can't find any pattern to it.


Could this be because of the global g_Info variable?

For what its worth, I implement a similar pattern when doing session state, however, I expose my object using a singleton pattern.

Code Example:

class SessionManager
{
private const string SESSION_MANAGER = "SESSION_MANAGER";
private string username;

private SessionManager()
{
}

public string UserName
{
get { return username; }
set { username = value; }
}

public static SessionManager Instance
{
SessionManager manager = HttpContext.Current.Session[SESSION_MANAGER] as SessionManager;
if (manager == null)
{
manager = new SessionManager();
HttpContext.Current.Session[SESSION_MANAGER] = manager;
}
return manager;
}
}

When I want to access the session state in the code, I type
SessionManager.Instance.UserName = "someValue"; or
string someValue = SessionManager.Instance.UserName;

The idea is quite similiar to yours, and this should resolve your problems.

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #2

P: n/a
A module is a class with shared variables (possibly as private members). As
such all users are sharing the same g_Info.

"Boban Dragojlovic" <news@_N_O_S_P_AM_dragojlovic.org> a écrit dans le
message de news:u6******************@newssvr27.news.prodigy.c om...

I'm building a complex web-based reservations system.

Gathering the user's data requires between 8 and 15 pages (depending on
which options they are interested in). I use the "Session" object to store the various elements as the user moves through the pages.

Rather than storing the preferences directly in the Session object (e.g.
Session("LastName") = ...), I created a class

<Serializable()> Public Class ReservationInfo

This class has private variables for all the data, and exposes properties to retrieve/manipulate the data. I did this for several reasons:
* I don't have to worry about screwing up variable names from one page
to the next (is it Session("OptionNumber") or is it Session("OptionNbr")) -- * I can add some logic related to the assignment of properties (e.g. if a property changes, I might need to reset other properties)
In one of my modules I declare

dim g_Info as ReservationInfo

And on each page, then, in the OnLoad event, I have something to this
effect:
g_Info = Current.Session("ReservationInfo")

(actually, in the OnLoad event I call a public sub in one of my
modules, and it does the retrieval. That's why it references
Current.Session)
and in the Unload event, I have
Session("ReservationInfo") = g_Info
This way my entire set of variables is loaded from the Session, and saved
back to the session each time.

I let .NET manage the Session object in memory (single server), and
everything works great (or at least it did during my development/testing).

The problem happened when we ran the first multi-user test (e.g. 5 people
testing at the same time).

Suddenly, as users moved from page to page, their session information was
getting swapped with the information from another user. Every so often
(every couple of pages or so), as you moved from one page to another, you
suddenly wound up with the data of another user on the system.
I then added logic so that in the unload event, it would serialize and dump the entire g_Info object to disk, and the filename would be based on the
SessionID of the user. That way I could trace the session information of
each user as they moved from page to page. I've confirmed that this happens there. It seems that when it retrieves the data from the Session object
g_Info = Current.Session("ReservationInfo")
it sometimes grabs the wrong data.

I've analyzed several hundred page requests, and found many occurrences, but can't find any pattern to it.
I don't have a clue how this could be. Any ideas?


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.