473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Public Variables

I am developing 3-tiered application. I have and ASP UI, VB.Net Business
Objects and a SQL ServerDB.

I am encountering a problem that I have a mental block on and would
appreciate some help.

When the user logs on and moves around the application, there is data that
is required by any business object that is instantiated in the Business
layer. An example of this data is UserID (I have about 15 other values that
I want to keep track of)

What I have tried is to have a class called clsAppData that contains all of
the values that I'm interested in:

Public Class clsAppData
Public UserID as Integer

Public Shared Function GetAppData as clsAppData
Return AppData
End Function
End Class

I then have a public variable declared in a module in my business layer
which is visible to all other objects in this layer:

Public Module modGlobals
Friend AppData as clsAppData
End Module


This works fine if only one session is active. If I have more than one
session, the AppData variable seems to be visible accross sessions. This is
not the behaviour I want. What I want is a variable that is visible to all
objects in my business layer, but only within the context of the ASP Session.

Could someone help me with this
tia

Terry Holland
May 18 '07 #1
5 1489


"Terry Holland" <MS***********@nospam.nospamwrote in message
news:0E**********************************@microsof t.com...
>I am developing 3-tiered application. I have and ASP UI, VB.Net Business
Objects and a SQL ServerDB.

I am encountering a problem that I have a mental block on and would
appreciate some help.

When the user logs on and moves around the application, there is data that
is required by any business object that is instantiated in the Business
layer. An example of this data is UserID (I have about 15 other values
that
I want to keep track of)

What I have tried is to have a class called clsAppData that contains all
of
the values that I'm interested in:

Public Class clsAppData
Public UserID as Integer

Public Shared Function GetAppData as clsAppData
Return AppData
End Function
End Class

I then have a public variable declared in a module in my business layer
which is visible to all other objects in this layer:

Public Module modGlobals
Friend AppData as clsAppData
End Module


This works fine if only one session is active. If I have more than one
session, the AppData variable seems to be visible accross sessions. This
is
not the behaviour I want. What I want is a variable that is visible to
all
objects in my business layer, but only within the context of the ASP
Session.

Could someone help me with this
tia

Terry Holland
I can't imagine needing that much information across all business layers
but, one solution (and probably not the best solution) would be to create a
class that implements the IIdentity object and place all that extra
information within properties of the derived class. The identity class
isn't really meant for this, but it's one way to do it. The Identity class
can then be passed to the Principal object (as part of it's constructor) and
the Principal can be attached to the Thread currently running. Then you can
access the Identity object through the Principal object through the Thread
object throughout all of your tiers (as long as all tiers are running on the
same thread on the same machine).

HTH,
Mythran
May 18 '07 #2
KJ
One easy (and perhaps naive) way to achieve this is to put your instance of
the special class in the Session, then, have your BL objects access it from
HttpContext.Current.Session

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:0E**********************************@microsof t.com...
>I am developing 3-tiered application. I have and ASP UI, VB.Net Business
Objects and a SQL ServerDB.

I am encountering a problem that I have a mental block on and would
appreciate some help.

When the user logs on and moves around the application, there is data that
is required by any business object that is instantiated in the Business
layer. An example of this data is UserID (I have about 15 other values
that
I want to keep track of)

What I have tried is to have a class called clsAppData that contains all
of
the values that I'm interested in:

Public Class clsAppData
Public UserID as Integer

Public Shared Function GetAppData as clsAppData
Return AppData
End Function
End Class

I then have a public variable declared in a module in my business layer
which is visible to all other objects in this layer:

Public Module modGlobals
Friend AppData as clsAppData
End Module


This works fine if only one session is active. If I have more than one
session, the AppData variable seems to be visible accross sessions. This
is
not the behaviour I want. What I want is a variable that is visible to
all
objects in my business layer, but only within the context of the ASP
Session.

Could someone help me with this
tia

Terry Holland

May 18 '07 #3
Correct me if I'm wrong but if you put this stuff in a Module in VB.NET then
its Shared (static). You need to put it in a class. Also, you might want to
look into Membership / Profile providers as the Profile is what this kind of
stuff was designed for.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Terry Holland" wrote:
I am developing 3-tiered application. I have and ASP UI, VB.Net Business
Objects and a SQL ServerDB.

I am encountering a problem that I have a mental block on and would
appreciate some help.

When the user logs on and moves around the application, there is data that
is required by any business object that is instantiated in the Business
layer. An example of this data is UserID (I have about 15 other values that
I want to keep track of)

What I have tried is to have a class called clsAppData that contains all of
the values that I'm interested in:

Public Class clsAppData
Public UserID as Integer

Public Shared Function GetAppData as clsAppData
Return AppData
End Function
End Class

I then have a public variable declared in a module in my business layer
which is visible to all other objects in this layer:

Public Module modGlobals
Friend AppData as clsAppData
End Module


This works fine if only one session is active. If I have more than one
session, the AppData variable seems to be visible accross sessions. This is
not the behaviour I want. What I want is a variable that is visible to all
objects in my business layer, but only within the context of the ASP Session.

Could someone help me with this
tia

Terry Holland
May 18 '07 #4
"Terry Holland" <MS***********@nospam.nospamwrote in message
news:0E**********************************@microsof t.com...
>I am developing 3-tiered application. I have and ASP UI, VB.Net Business
Objects and a SQL ServerDB.
....
I then have a public variable declared in a module in my business layer
which is visible to all other objects in this layer:

Public Module modGlobals
Friend AppData as clsAppData
End Module
You want to stop using modules in ASP.NET applications. You have found out
the easy way that the data in that module is shared across all sessions.
What you have not yet learned is that this requires locking if the data are
ever going to change.

You don't want to find that out the hard way, so stop using modules. They're
a holdover from VB6 days and have no place in object-oriented development.
--
John Saunders [MVP]
May 18 '07 #5
Thanks guys

Ive changed the way I do things so that Im passing necessary parameters to
my bo layer on each request
May 22 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jose Meireles | last post by:
Hi everyone, I'm trying to use public variables in a web form to hld specific values. What happens is that the public variables (declared as public x as y in the beginning of the class), doesn't...
6
by: darrel | last post by:
I'm still not quite sure how best to handle the passing of data between controls. This is a method I'm using at the moment: I have an XML file that contains a variety of page-centric...
4
by: Nick Dreyer | last post by:
Is it possible to see public class variables of a COM addin in Excel 97 VBA? I have successfully created the (Visual Basic 2003 .NET) COM and referenced it in an Excel 97 VBA project. The VBA...
27
by: thomasp | last post by:
Variables that I would like to make available to all forms and modules in my program, where should I declare them? At the momment I just created a module and have them all declared public there. ...
2
by: Jose Meireles | last post by:
Hi everyone, I'm trying to use public variables in a web form to hld specific values. What happens is that the public variables (declared as public x as y in the beginning of the class), doesn't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.