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

Muliple Users aspx project

P: n/a
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

Nov 19 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
<gr******@comcast.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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
Nov 19 '05 #2

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

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
<gr******@comcast.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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

Nov 19 '05 #3

P: n/a
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?

Nov 19 '05 #4

P: n/a
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
<gr******@comcast.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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?

Nov 19 '05 #5

P: n/a
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.

Nov 19 '05 #6

P: n/a
<gr******@comcast.net> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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/de...sp?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
Nov 19 '05 #7

P: n/a
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

<gr******@comcast.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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

Nov 19 '05 #8

P: n/a
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.
B. Comrie wrote:
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

<gr******@comcast.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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


Nov 19 '05 #9

P: n/a
<gr******@comcast.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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
Nov 19 '05 #10

P: n/a
so, on webform1 I can "declare" the variable like this

session("FirstName") = txtfirstname.text

and then display it on , say, page 4 with

lblfirstname.text = session("FirstName")?

also, can you calculate with these variables like

session("Subtotal") = session("Integer1") * session("Integer2")?

Thanks again
John Saunders wrote:
<gr******@comcast.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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


Nov 19 '05 #11

P: n/a
<gr******@comcast.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
so, on webform1 I can "declare" the variable like this

session("FirstName") = txtfirstname.text

and then display it on , say, page 4 with

lblfirstname.text = session("FirstName")?

also, can you calculate with these variables like

session("Subtotal") = session("Integer1") * session("Integer2")?
No, because "*" is not a valid operator for the Object type.

You'll need

Session("Subtotal") = DirectCast(Session("Integer1"), Integer) *
DirectCast(Session("Integer2"), Integer)

You _are_ running with Options Strict On, aren't you?

John Saunders
Thanks again
John Saunders wrote:
<gr******@comcast.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
> 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

Nov 19 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.