Link to home
Start Free TrialLog in
Avatar of wsturdev
wsturdevFlag for United States of America

asked on

URGENT - User logs in and is suddenly looking at another user's data

I have created a web site in VB.Net.

User1 logs in and after doing so sees a screen with a list of Items assigned to him.  His name and other information have been retrieved and appears at various points on the screen.

User2 logs in and after clicking around, ends up looking at the same screen as User1 is looking at, but it contains User1's data and name etc.

It is almost as if a public variable that is used to control what is appearing on the screen is being shared by the two sessions!!!  I thought multiple sessions were much the same as multiple instances of the code running.

Or it looks as if the stored procedure they are both using to retrieve data from SQL Server is somehow being shared between them.  Could this be?  I thought the usage of a stored procedure within multiple sessions resulted in multiple instances of results.

Any ideas?

My variables are all declared in a module.  Are they somehow being shared?  e.g.
    Public strUserID As String
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Variables declared in a module are shared across the entire application, so everyone gets the same variable space.

Bob
Avatar of pauljk1619
pauljk1619

Are these users using the same machine?  If so, it's probably a caching issue.  Pages are stored in cache and retrieved from there to make things faster.  Unfortunately, it sometimes pulls up the wrong data with it.  You can code your pages to disallow a page to be cached or you can short the time a page can remain in the cache.
Avatar of wsturdev

ASKER

One user is in Florida and one is in Seattle.  I need variables to carry information across the various forms during execution for a single user.  Where do I put them so they can only be used in that way?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Where are you putting them now?  In the Session?
Yes...  or you can pass variables via the querysting
Bob -- I had no sense of a "Session" concept.  I have been putting my variables in a Module, knowing they would be shared between pages, but also thinking they would not be shared between what I now understand are Sessions.

If my understanding is now correct, putting them in the "Session" makes sense:

An assembly creates an application.  When the web server starts, the assembled application starts (or when the first user tries to access it).  A session is a user's activity within the application (viewing web pages).  Some variables and routines can be shared across all sessions (users), but some things can be protected within a session (user) so no other session (user) can see them.  Further protection/isolation of variables can be achieved within a Session by declaring them within a function or subroutine.

So, where is the "Session Level"?


pauljk1619 -- Yes I understand about the querystring, but in this case I prefer to place them in a central location so as to keep track of them more logical (for me, anyway).
Here is a Micro$oft KB article that talks about the differences:

INFO: ASP.NET State Management Overview
http://support.microsoft.com/default.aspx?scid=kb;en-us;307598

Application State
Application state variables are, in effect, global variables for each ASP.NET application. You can share values of these variables throughout that application. These variables are usually set in the Application_OnStart event and then accessed and modified in individual ASP.NET pages.

The lifetime of application variables spans through the lifetime of the ASP.NET application until the application is unloaded.

Session State
You can store values that need to be persisted for the duration of a user's session in session variables. These variables are unique to each user session and can be accessed in any ASP.NET page within an application. You can set and access session information from within an ASP.NET application.

Bob
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have set up my Session variables as follows in my Global.asax object:

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the session is started
        Dim strUserID As String = Session("strUserID")
    End Sub


I modified all the code to reference the variables as Session("strUserID"), but now, I have this routine in myModule.vb:

Public Function GetLoggedInUserID() As String
        GetLoggedInUserID = Session("strUserID")
    End Function

and I am getting a build error saying Name 'Session' is not declared

Should I be moving such functions to somehwere else?
As I was modifying code and experimenting, I discovered I no longer needed those functions, so I commented them out.  Everything seems to be working properly now and testing so far shows there is not longer any cross-over of data.