Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Public Variables

Reply
Thread Tools

Public Variables

 
 
=?Utf-8?B?VGVycnkgSG9sbGFuZA==?=
Guest
Posts: n/a
 
      05-18-2007
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
 
Reply With Quote
 
 
 
 
Mythran
Guest
Posts: n/a
 
      05-18-2007


"Terry Holland" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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


 
Reply With Quote
 
 
 
 
KJ
Guest
Posts: n/a
 
      05-18-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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



 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      05-18-2007
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

 
Reply With Quote
 
John Saunders [MVP]
Guest
Posts: n/a
 
      05-18-2007
"Terry Holland" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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]


 
Reply With Quote
 
=?Utf-8?B?VGVycnkgSG9sbGFuZA==?=
Guest
Posts: n/a
 
      05-22-2007
Thanks guys

Ive changed the way I do things so that Im passing necessary parameters to
my bo layer on each request
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSE 4 11-15-2006 02:40 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSD 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb Charles A. Lackman ASP .Net 1 12-08-2004 07:08 PM



Advertisments