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

Public variables in a module - from 2 users affect each other

P: n/a
Hi All!

I have a question, i have a web application and I store some member
information in a variable i declared in a module like:

Public some_info_variable as string
in module1.vb

But when another user comes to my website he is getting the same values from
the variable!!!
And i want the variable to be filled/read unique for each session/user.

I found this:
--------------------------------------------------
Using a module may be your problem. Depending on what kind of app (from
list above) it is. It also might not be. Modules may give you problems in
ASP.NET apps for example, as module level variables are shared across the
entire app. Each session would see the exact same variable. If each company
is using the same web server...
--------------------------------------------------

i found it @:
http://groups.google.nl/group/micros...b4ace6fa68c8c1

But what is the correct way to declare my variable i need in all my pages
but only for 1 user?!?!!

Thanks in advance!

Best regards

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


P: n/a
Store the variable in Session("VariableName") as this is unique to each
session. For global variables, store int Application("VariableName") and for
controls/page class level variable to persist, store them in
Viewstate("VariableName")

HTH MR N

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
Hi All!

I have a question, i have a web application and I store some member
information in a variable i declared in a module like:

Public some_info_variable as string
in module1.vb

But when another user comes to my website he is getting the same values
from the variable!!!
And i want the variable to be filled/read unique for each session/user.

I found this:
--------------------------------------------------
Using a module may be your problem. Depending on what kind of app (from
list above) it is. It also might not be. Modules may give you problems in
ASP.NET apps for example, as module level variables are shared across the
entire app. Each session would see the exact same variable. If each
company
is using the same web server...
--------------------------------------------------

i found it @:
http://groups.google.nl/group/micros...b4ace6fa68c8c1

But what is the correct way to declare my variable i need in all my pages
but only for 1 user?!?!!

Thanks in advance!

Best regards

Floris

Nov 19 '05 #2

P: n/a
Hi,

Thanks for your very fast reply!

Ok, but will the session("item") work on browsers without cookies enabled
on the browser?

And i have a "Public input As New System.Collections.SortedList"
How do i create a sortedlist unique for each session?

Thanks again!

Best regards

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:ur**************@TK2MSFTNGP14.phx.gbl...
Store the variable in Session("VariableName") as this is unique to each
session. For global variables, store int Application("VariableName") and
for controls/page class level variable to persist, store them in
Viewstate("VariableName")

HTH MR N

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
Hi All!

I have a question, i have a web application and I store some member
information in a variable i declared in a module like:

Public some_info_variable as string
in module1.vb

But when another user comes to my website he is getting the same values
from the variable!!!
And i want the variable to be filled/read unique for each session/user.

I found this:
--------------------------------------------------
Using a module may be your problem. Depending on what kind of app (from
list above) it is. It also might not be. Modules may give you problems in
ASP.NET apps for example, as module level variables are shared across the
entire app. Each session would see the exact same variable. If each
company
is using the same web server...
--------------------------------------------------

i found it @:
http://groups.google.nl/group/micros...b4ace6fa68c8c1

But what is the correct way to declare my variable i need in all my pages
but only for 1 user?!?!!

Thanks in advance!

Best regards

Floris


Nov 19 '05 #3

P: n/a
So the next question is : How do i declare a sortedlist unique for eachs
ession that i can read from each module file ?
and cannot be read by other sessions ofcourse.

BR

Floris
"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> schreef in bericht
news:43***********************@news.xs4all.nl...
Hi,

Thanks for your very fast reply!

Ok, but will the session("item") work on browsers without cookies enabled
on the browser?

And i have a "Public input As New System.Collections.SortedList"
How do i create a sortedlist unique for each session?

Thanks again!

Best regards

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:ur**************@TK2MSFTNGP14.phx.gbl...
Store the variable in Session("VariableName") as this is unique to each
session. For global variables, store int Application("VariableName") and
for controls/page class level variable to persist, store them in
Viewstate("VariableName")

HTH MR N

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
Hi All!

I have a question, i have a web application and I store some member
information in a variable i declared in a module like:

Public some_info_variable as string
in module1.vb

But when another user comes to my website he is getting the same values
from the variable!!!
And i want the variable to be filled/read unique for each session/user.

I found this:
--------------------------------------------------
Using a module may be your problem. Depending on what kind of app (from
list above) it is. It also might not be. Modules may give you problems
in
ASP.NET apps for example, as module level variables are shared across
the
entire app. Each session would see the exact same variable. If each
company
is using the same web server...
--------------------------------------------------

i found it @:
http://groups.google.nl/group/micros...b4ace6fa68c8c1

But what is the correct way to declare my variable i need in all my
pages but only for 1 user?!?!!

Thanks in advance!

Best regards

Floris



Nov 19 '05 #4

P: n/a
The webconfig can be set to use cookiless operations "Cookie Munging" if not
all your browsers support cookies, this stores the sessionID into the URL

A session is unique to the browser which opened it ( or should be ).

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
So the next question is : How do i declare a sortedlist unique for eachs
ession that i can read from each module file ?
and cannot be read by other sessions ofcourse.

BR

Floris
"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> schreef in bericht
news:43***********************@news.xs4all.nl...
Hi,

Thanks for your very fast reply!

Ok, but will the session("item") work on browsers without cookies
enabled on the browser?

And i have a "Public input As New System.Collections.SortedList"
How do i create a sortedlist unique for each session?

Thanks again!

Best regards

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:ur**************@TK2MSFTNGP14.phx.gbl...
Store the variable in Session("VariableName") as this is unique to each
session. For global variables, store int Application("VariableName") and
for controls/page class level variable to persist, store them in
Viewstate("VariableName")

HTH MR N

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
Hi All!

I have a question, i have a web application and I store some member
information in a variable i declared in a module like:

Public some_info_variable as string
in module1.vb

But when another user comes to my website he is getting the same values
from the variable!!!
And i want the variable to be filled/read unique for each session/user.

I found this:
--------------------------------------------------
Using a module may be your problem. Depending on what kind of app (from
list above) it is. It also might not be. Modules may give you problems
in
ASP.NET apps for example, as module level variables are shared across
the
entire app. Each session would see the exact same variable. If each
company
is using the same web server...
--------------------------------------------------

i found it @:
http://groups.google.nl/group/micros...b4ace6fa68c8c1

But what is the correct way to declare my variable i need in all my
pages but only for 1 user?!?!!

Thanks in advance!

Best regards

Floris



Nov 19 '05 #5

P: n/a
Ok i understand the session part.

now the only thing I want to know is how to declare a sortedlist
(System.Collections.SortedList) unique for each session and can be read thru
my entire application (all pages....)

Br

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:%2****************@TK2MSFTNGP14.phx.gbl...
The webconfig can be set to use cookiless operations "Cookie Munging" if
not all your browsers support cookies, this stores the sessionID into the
URL

A session is unique to the browser which opened it ( or should be ).

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
So the next question is : How do i declare a sortedlist unique for eachs
ession that i can read from each module file ?
and cannot be read by other sessions ofcourse.

BR

Floris
"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> schreef in bericht
news:43***********************@news.xs4all.nl...
Hi,

Thanks for your very fast reply!

Ok, but will the session("item") work on browsers without cookies
enabled on the browser?

And i have a "Public input As New System.Collections.SortedList"
How do i create a sortedlist unique for each session?

Thanks again!

Best regards

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:ur**************@TK2MSFTNGP14.phx.gbl...
Store the variable in Session("VariableName") as this is unique to each
session. For global variables, store int Application("VariableName")
and for controls/page class level variable to persist, store them in
Viewstate("VariableName")

HTH MR N

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
> Hi All!
>
> I have a question, i have a web application and I store some member
> information in a variable i declared in a module like:
>
> Public some_info_variable as string
> in module1.vb
>
> But when another user comes to my website he is getting the same
> values from the variable!!!
> And i want the variable to be filled/read unique for each
> session/user.
>
> I found this:
> --------------------------------------------------
> Using a module may be your problem. Depending on what kind of app
> (from
> list above) it is. It also might not be. Modules may give you problems
> in
> ASP.NET apps for example, as module level variables are shared across
> the
> entire app. Each session would see the exact same variable. If each
> company
> is using the same web server...
> --------------------------------------------------
>
> i found it @:
> http://groups.google.nl/group/micros...b4ace6fa68c8c1
>
> But what is the correct way to declare my variable i need in all my
> pages but only for 1 user?!?!!
>
> Thanks in advance!
>
> Best regards
>
> Floris
>



Nov 19 '05 #6

P: n/a
Dim MySortedList as System.Collections.SortedList

In the page load event for your entry page , something like this. . . . .

If Not IsPostBack
MySortedList = DO THE ASSIGNMENT HERE FROM YOUR DATA
Session("MySortedList") = MySortedList
Else
MySortedList = Session("MySortedList")
End If

And for each other non entry page.

MySortedList = Session("MySortedList")


"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
Ok i understand the session part.

now the only thing I want to know is how to declare a sortedlist
(System.Collections.SortedList) unique for each session and can be read
thru my entire application (all pages....)

Br

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:%2****************@TK2MSFTNGP14.phx.gbl...
The webconfig can be set to use cookiless operations "Cookie Munging" if
not all your browsers support cookies, this stores the sessionID into the
URL

A session is unique to the browser which opened it ( or should be ).

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
So the next question is : How do i declare a sortedlist unique for eachs
ession that i can read from each module file ?
and cannot be read by other sessions ofcourse.

BR

Floris
"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> schreef in bericht
news:43***********************@news.xs4all.nl...
Hi,

Thanks for your very fast reply!

Ok, but will the session("item") work on browsers without cookies
enabled on the browser?

And i have a "Public input As New System.Collections.SortedList"
How do i create a sortedlist unique for each session?

Thanks again!

Best regards

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:ur**************@TK2MSFTNGP14.phx.gbl...
> Store the variable in Session("VariableName") as this is unique to
> each session. For global variables, store int
> Application("VariableName") and for controls/page class level variable
> to persist, store them in Viewstate("VariableName")
>
> HTH MR N
>
>
>
>
>
> "Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
> news:43***********************@news.xs4all.nl...
>> Hi All!
>>
>> I have a question, i have a web application and I store some member
>> information in a variable i declared in a module like:
>>
>> Public some_info_variable as string
>> in module1.vb
>>
>> But when another user comes to my website he is getting the same
>> values from the variable!!!
>> And i want the variable to be filled/read unique for each
>> session/user.
>>
>> I found this:
>> --------------------------------------------------
>> Using a module may be your problem. Depending on what kind of app
>> (from
>> list above) it is. It also might not be. Modules may give you
>> problems in
>> ASP.NET apps for example, as module level variables are shared across
>> the
>> entire app. Each session would see the exact same variable. If each
>> company
>> is using the same web server...
>> --------------------------------------------------
>>
>> i found it @:
>> http://groups.google.nl/group/micros...b4ace6fa68c8c1
>>
>> But what is the correct way to declare my variable i need in all my
>> pages but only for 1 user?!?!!
>>
>> Thanks in advance!
>>
>> Best regards
>>
>> Floris
>>
>
>



Nov 19 '05 #7

P: n/a
And there is no other way that i can like declare a variable in
default.aspx.vb:

dim test as string

and then modify it in functions.vb like:

test = 3

I want all my default functions in a seperate file.... now i stored them in
a module... functions.vb

BR

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:Oc****************@TK2MSFTNGP15.phx.gbl...
Dim MySortedList as System.Collections.SortedList

In the page load event for your entry page , something like this. . . . .

If Not IsPostBack
MySortedList = DO THE ASSIGNMENT HERE FROM YOUR DATA
Session("MySortedList") = MySortedList
Else
MySortedList = Session("MySortedList")
End If

And for each other non entry page.

MySortedList = Session("MySortedList")


"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
Ok i understand the session part.

now the only thing I want to know is how to declare a sortedlist
(System.Collections.SortedList) unique for each session and can be read
thru my entire application (all pages....)

Br

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:%2****************@TK2MSFTNGP14.phx.gbl...
The webconfig can be set to use cookiless operations "Cookie Munging" if
not all your browsers support cookies, this stores the sessionID into
the URL

A session is unique to the browser which opened it ( or should be ).

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
So the next question is : How do i declare a sortedlist unique for
eachs ession that i can read from each module file ?
and cannot be read by other sessions ofcourse.

BR

Floris
"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> schreef in bericht
news:43***********************@news.xs4all.nl...
> Hi,
>
> Thanks for your very fast reply!
>
> Ok, but will the session("item") work on browsers without cookies
> enabled on the browser?
>
> And i have a "Public input As New System.Collections.SortedList"
> How do i create a sortedlist unique for each session?
>
> Thanks again!
>
> Best regards
>
> Floris
>
>
> "Mr Newbie" <he**@now.com> schreef in bericht
> news:ur**************@TK2MSFTNGP14.phx.gbl...
>> Store the variable in Session("VariableName") as this is unique to
>> each session. For global variables, store int
>> Application("VariableName") and for controls/page class level
>> variable to persist, store them in Viewstate("VariableName")
>>
>> HTH MR N
>>
>>
>>
>>
>>
>> "Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
>> news:43***********************@news.xs4all.nl...
>>> Hi All!
>>>
>>> I have a question, i have a web application and I store some member
>>> information in a variable i declared in a module like:
>>>
>>> Public some_info_variable as string
>>> in module1.vb
>>>
>>> But when another user comes to my website he is getting the same
>>> values from the variable!!!
>>> And i want the variable to be filled/read unique for each
>>> session/user.
>>>
>>> I found this:
>>> --------------------------------------------------
>>> Using a module may be your problem. Depending on what kind of app
>>> (from
>>> list above) it is. It also might not be. Modules may give you
>>> problems in
>>> ASP.NET apps for example, as module level variables are shared
>>> across the
>>> entire app. Each session would see the exact same variable. If each
>>> company
>>> is using the same web server...
>>> --------------------------------------------------
>>>
>>> i found it @:
>>> http://groups.google.nl/group/micros...b4ace6fa68c8c1
>>>
>>> But what is the correct way to declare my variable i need in all my
>>> pages but only for 1 user?!?!!
>>>
>>> Thanks in advance!
>>>
>>> Best regards
>>>
>>> Floris
>>>
>>
>>
>
>



Nov 19 '05 #8

P: n/a
Hi Floris,
now the only thing I want to know is how to declare a sortedlist
(System.Collections.SortedList) unique for each session and can be read
thru my entire application (all pages....)
That is a bit more complicated. If I understand you correctly, you want a
Sorted List that is unique to every Session, yet available to every other
Session. For that, you need the Application space, in particular, the
Application Cache, which is also a Collection, but is available to every
Session, in fact, to the entire Application.

What I would do is not store the Sorted Lists in Session State, but in the
Application Cache. The Application Cache is a Dictionary like the Session,
so you could set the Key to the Session ID for a particular user Session,
and the Value to the Sorted List that belongs to that Session. Example:

Cache.Insert(Session.SessionID, YourSessionSortedList, null,
DateTime.MaxValue, TimeSpan.FromMinutes(21));

Items in the Application Cache have configurable expiration associated with
them, so another alternative is to set the expiration for the item in the
Application Cache to a little longer than the expiration for the Session.
You would need to add an Event Handler to (probably) the
PreRequestHandlerExecute Event in the global.asax file. The Session should
be available at that time. You can't literally update the expiration of an
item in the Cache, but you can renew it by first obtaining a reference to it
(object = (objectType)Cache["KeyName"] - in this case the SessionID), and
then reinsert it with

Cache.Insert(Session.SessionID, YourSessionSortedList, null,
DateTime.MaxValue, TimeSpan.FromMinutes(21));

As it has the same Key as the original Cache Item, it will overwrite it.

This method will enable the Application Cache to manage itself. One minute
after the Session dies from lack of Requests, the item in the Cache will
also expire.

Finally, avoid using Modules in your app. Not only are they totally global
and singletons, rather than instances, they are not Thread-safe. If you need
a static item, create it in a class. Only that item will be static. The rest
of the class will not be. And be careful in general of using static items.
When you can, use the containers such as Application, Session, and Page to
do your caching.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
I'd rather be a hammer than a nail.

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl... Ok i understand the session part.

now the only thing I want to know is how to declare a sortedlist
(System.Collections.SortedList) unique for each session and can be read
thru my entire application (all pages....)

Br

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:%2****************@TK2MSFTNGP14.phx.gbl...
The webconfig can be set to use cookiless operations "Cookie Munging" if
not all your browsers support cookies, this stores the sessionID into the
URL

A session is unique to the browser which opened it ( or should be ).

"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
news:43***********************@news.xs4all.nl...
So the next question is : How do i declare a sortedlist unique for eachs
ession that i can read from each module file ?
and cannot be read by other sessions ofcourse.

BR

Floris
"Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> schreef in bericht
news:43***********************@news.xs4all.nl...
Hi,

Thanks for your very fast reply!

Ok, but will the session("item") work on browsers without cookies
enabled on the browser?

And i have a "Public input As New System.Collections.SortedList"
How do i create a sortedlist unique for each session?

Thanks again!

Best regards

Floris
"Mr Newbie" <he**@now.com> schreef in bericht
news:ur**************@TK2MSFTNGP14.phx.gbl...
> Store the variable in Session("VariableName") as this is unique to
> each session. For global variables, store int
> Application("VariableName") and for controls/page class level variable
> to persist, store them in Viewstate("VariableName")
>
> HTH MR N
>
>
>
>
>
> "Floris van Haaster" <fl****@NO-SPAM-datasmit.nl> wrote in message
> news:43***********************@news.xs4all.nl...
>> Hi All!
>>
>> I have a question, i have a web application and I store some member
>> information in a variable i declared in a module like:
>>
>> Public some_info_variable as string
>> in module1.vb
>>
>> But when another user comes to my website he is getting the same
>> values from the variable!!!
>> And i want the variable to be filled/read unique for each
>> session/user.
>>
>> I found this:
>> --------------------------------------------------
>> Using a module may be your problem. Depending on what kind of app
>> (from
>> list above) it is. It also might not be. Modules may give you
>> problems in
>> ASP.NET apps for example, as module level variables are shared across
>> the
>> entire app. Each session would see the exact same variable. If each
>> company
>> is using the same web server...
>> --------------------------------------------------
>>
>> i found it @:
>> http://groups.google.nl/group/micros...b4ace6fa68c8c1
>>
>> But what is the correct way to declare my variable i need in all my
>> pages but only for 1 user?!?!!
>>
>> Thanks in advance!
>>
>> Best regards
>>
>> Floris
>>
>
>



Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.