Public Variables

Discussion in 'ASP .Net' started by =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=, May 18, 2007.

  1. 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
    =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=, May 18, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=

    Mythran Guest

    "Terry Holland" <> wrote in message
    news:...
    >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
    Mythran, May 18, 2007
    #2
    1. Advertising

  3. =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=

    KJ Guest

    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" <> wrote in message
    news:...
    >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
    KJ, May 18, 2007
    #3
  4. 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
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, May 18, 2007
    #4
  5. "Terry Holland" <> wrote in message
    news:...
    >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]
    John Saunders [MVP], May 18, 2007
    #5
  6. Thanks guys

    Ive changed the way I do things so that Im passing necessary parameters to
    my bo layer on each request
    =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=, May 22, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,330
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    534
    SpamProof
    Oct 21, 2003
  3. avnrao
    Replies:
    0
    Views:
    3,354
    avnrao
    May 7, 2004
  4. Kevin Spencer
    Replies:
    2
    Views:
    3,295
    Kevin Spencer
    Sep 15, 2004
  5. Steve Mauldin
    Replies:
    5
    Views:
    1,713
    Steve Mauldin
    Jan 26, 2006
Loading...

Share This Page