Muliple Users aspx project

G

grizduck

Hi-

I have created a .NET web application that uses 6 aspx pages. As the
users goes from one page to the next several variables are set and
displayed on future pages. I found out today that if one person is on
Step 4, for instance, if another user goes to Step 3, all of the
information the 1st user entered displays. Am I missing a setting in
Webconfig or in IIS that allows each user to get their own instance of
the program? Any help is needed as I am on a tight timeline. Thanks
 
J

John Saunders

Hi-

I have created a .NET web application that uses 6 aspx pages. As the
users goes from one page to the next several variables are set and
displayed on future pages. I found out today that if one person is on
Step 4, for instance, if another user goes to Step 3, all of the
information the 1st user entered displays. Am I missing a setting in
Webconfig or in IIS that allows each user to get their own instance of
the program?

There is no "program" for users to get an instance of. Please go to MSDN and
read about the ASP.NET page lifecycle.

Your pages use global variables. NEVER use global variables. Use Session
state to give each user a separate copy of some data.

John Saunders
 
K

Karl Seguin

Seems like something's wrong with your code. Where are these values being
stored? The application variable?

Karl
 
G

grizduck

I am using Global variables stored in a module. The guy above says to
use session state. I am new to this and am not really sure what that
is. Can you help?
 
K

Karl Seguin

Griz:
Check out my article on this:
http://openmymind.net/DataStorage/index.html

It should be helpful. I'd like to see the global variable code...is it
something like:

public shared SomeVaraible as Something?

or Application.Add("SomeKey", Something) or what? you could provide SOME
code to get some more meaningful help...

Karl
 
G

grizduck

the code is something like this

public gsFirstName as string
public gsLastName as string

Then I capture the variables on the first page, and display it again on
the fourth page. I do this with several variables. When one user has
given the variables a value, another user somewhere else will display
that value when they go to the appropriate page. So, all users are
sharing the same variables, and I can't have that happen. I am used to
VB6 windows forms, and didn't realize this would happen with webforms.
 
J

John Saunders

the code is something like this

public gsFirstName as string
public gsLastName as string

This is exactly your problem. Please do yourself a big favor and read The
ASP.NET Page Object Model
(http://msdn.microsoft.com/library/d...pp/html/aspnet-pageobjectmodel.asp?frame=true).
Web forms are very different from Windows Forms, and .NET is very different
from VB6.

Many of the things you are used to from VB6 are just plain wrong with Web
Forms, and even with VB.NET in general. In particular, I strongly recommend
that anyone coming from VB6 should replace every single Module with the
equivalent Class. Modules are totally foreign to .NET and I believe it was
a mistake on the part of Microsoft to support them as is (there should have
been a converter).

If your Module had been a class, it might have been more obvious to you that
there was never going to be more than one instance of gsFirstName across all
users, as you would have declared it as:

Public Shared gsFirstName As String


John Saunders
 
B

B. Comrie

public gsFirstName as string
public gsLastName as string

IE: gsFirstName = TheFirstNameValue

These are available to evryone using the application, instead use Session
Variables, they are available to only the active users session.

Session("FirstName") = TheFirstNameValue
Session("LastName") = TheLastNameValue

B Comrie
http://www.codewidgets.com
 
G

grizduck

This is very helpful. I have one question though. Where do i declare
the session variables? Since I ran into this problem, I have been
reading many groups and researching the problem. Do I declare the
variables in global.asax or on each webform? Thanks in advance.
 
J

John Saunders

This is very helpful. I have one question though. Where do i declare
the session variables? Since I ran into this problem, I have been
reading many groups and researching the problem. Do I declare the
variables in global.asax or on each webform? Thanks in advance.

You don't have to declare them at all. They're not "variables", really.

"Session" (aka Page.Session, or Page.Context.Session) is an instance of the
HttpSessionState class. You can treat it as a collection of name-value
pairs. You can set a value with syntax like

Session("FirstName") = TheFirstNameValue

and then you can retrieve it with

Dim o As Object = Session("FirstName")

Note that Session(string) returns an Object, so you'll have to cast it to
the correct type:

Dim s As String = DirectCast(Session("FirstName"), String)

Note the use of DirectCast, which is correct since you know that it's a
string (you put it there, after all). Do not use CType or ToString in these
cases, as though you didn't know what type of value you put there.

Note also that this is subject to spelling errors - Session("FirstNam") will
return Nothing. I usually solve this problem by wrapping session state in a
class and using properties of the class to access it:

Public Class UserState
....
Public Shared Property FirstName As String
Get
Return DirectCast(HttpContext.Current.Session("FirstName"),
String)
End Get
Set(ByVal Value As String)
HttpContext.Current.Session("FirstName") = Value
End Set
End Property
...
End Class

This way, there are only two places for a typo to happen. I would access
this from a page as UserState.FirstName. This can be accessed from multiple
pages.

BTW, Note the use of HttpContext.Current.Session. Since class UserState
isn't a Page, it doesn't have a "Session" member, so the Shared HttpContext
member "Current" is used to access the current request context.


John Saunders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top