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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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.
wsturdevAuthor Commented:
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?
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Bob LearnedCommented:
If you are sharing variables between users, you can define the variable at the Application level or in a module.  But, if you are sharing variables across pages for a single user, then define them at the Session level.

Session("Name") = "Bob"

Dim name As String = Session("Name")


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Where are you putting them now?  In the Session?
Yes...  or you can pass variables via the querysting
wsturdevAuthor Commented:
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).
Bob LearnedCommented:
Here is a Micro$oft KB article that talks about the differences:

INFO: ASP.NET State Management Overview

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.

using System.Web.SessionState;

Session.Add(string name,object value)

You can retrieve with Session(name).ToString()
wsturdevAuthor Commented:
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?
wsturdevAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.