Carrying Objects

Discussion in 'ASP .Net' started by tshad, Oct 7, 2005.

  1. tshad

    tshad Guest

    I have a User object that has all the information on the object (firstName,
    LastName, email, userName, password, address, gender, dob etc).

    I want to only carry in a session variable the logon information (firstName,
    LastName, email, userName, password).

    Is it best to just carry all the information or create a different object
    with just a subset of the information?

    I am concerned with efficiency and speed here. If I am carrying a lot of
    large objects, I assume that would eat more memory and slow down processing.

    Thanks,

    Tom
     
    tshad, Oct 7, 2005
    #1
    1. Advertising

  2. tshad

    Lucas Tam Guest

    "tshad" <> wrote in
    news::

    > I have a User object that has all the information on the object
    > (firstName, LastName, email, userName, password, address, gender, dob
    > etc).
    >
    > I want to only carry in a session variable the logon information
    > (firstName, LastName, email, userName, password).
    >
    > Is it best to just carry all the information or create a different
    > object with just a subset of the information?
    >
    > I am concerned with efficiency and speed here. If I am carrying a lot
    > of large objects, I assume that would eat more memory and slow down
    > processing.


    Considering this object is only storing text information - it's probably
    not going to impact your application too much.

    But you might want to extend IIdentity instead - this object is attached
    to each authenticated session when it gets authentication and it would
    be a good place to place additional user properties.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-
    us/cpref/html/frlrfsystemsecurityprincipaliidentityclasstopic.asp


    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.

    Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
     
    Lucas Tam, Oct 7, 2005
    #2
    1. Advertising

  3. tshad

    Karl Seguin Guest

    One solution is to use composition, where one object is composed of another.

    pulblic class UserData
    {
    private string _firstName;
    private string _userName;
    ...
    public string FirstName{
    get { return _firstName; }
    set { _firstName = value;
    }
    public string UserName{
    get { return _userName; }
    set { _userName= value;
    }
    }

    public class User
    {
    private UserData _userData;
    private DateTime _dob;
    ...
    public DateTime Dob{
    get { return _dob; }
    set { _dob = value; }
    }
    //User is composed of userData, but exposes the properties as though they
    are part of it (no one exteranlly needs to know that we are using
    composition)
    public string FirstName{
    get { return userData.FirstName; }
    set { _userData.FirstName = value;
    }
    public string UserName{
    get { return userData.UserName; }
    set { userData.UserName= value;
    }

    //get the core data to store in ur session
    public UserData CoreData{
    get { return _userData;}
    }

    //create a new user based on the core-data
    public User(UserData coreData)
    {
    _userData = coreData;
    }
    }



    you can then do stuff like:

    User user = User.GetUser(1);
    Session["CurrentUser"] = user.CodeData;



    and then re-create ur user via:


    User user =new User((UserData)Session["CurrentUser"]);


    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/
    "tshad" <> wrote in message
    news:...
    >I have a User object that has all the information on the object (firstName,
    >LastName, email, userName, password, address, gender, dob etc).
    >
    > I want to only carry in a session variable the logon information
    > (firstName, LastName, email, userName, password).
    >
    > Is it best to just carry all the information or create a different object
    > with just a subset of the information?
    >
    > I am concerned with efficiency and speed here. If I am carrying a lot of
    > large objects, I assume that would eat more memory and slow down
    > processing.
    >
    > Thanks,
    >
    > Tom
    >
     
    Karl Seguin, Oct 7, 2005
    #3
  4. tshad

    tshad Guest

    "Lucas Tam" <> wrote in message
    news:Xns96E8979E6D941nntprogerscom@127.0.0.1...
    > "tshad" <> wrote in
    > news::
    >
    >> I have a User object that has all the information on the object
    >> (firstName, LastName, email, userName, password, address, gender, dob
    >> etc).
    >>
    >> I want to only carry in a session variable the logon information
    >> (firstName, LastName, email, userName, password).
    >>
    >> Is it best to just carry all the information or create a different
    >> object with just a subset of the information?
    >>
    >> I am concerned with efficiency and speed here. If I am carrying a lot
    >> of large objects, I assume that would eat more memory and slow down
    >> processing.

    >
    > Considering this object is only storing text information - it's probably
    > not going to impact your application too much.
    >
    > But you might want to extend IIdentity instead - this object is attached
    > to each authenticated session when it gets authentication and it would
    > be a good place to place additional user properties.


    That is probably true, but I haven't worked with that yet and is my next
    step, but I need to get this working simply first and then add that later.
    May be a little more work, but am under a time crunch here.

    Thanks,

    Tom
    >
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-
    > us/cpref/html/frlrfsystemsecurityprincipaliidentityclasstopic.asp
    >
    >
    > --
    > Lucas Tam ()
    > Please delete "REMOVE" from the e-mail address when replying.
    >
    > Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
     
    tshad, Oct 7, 2005
    #4
    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. Ani
    Replies:
    1
    Views:
    368
    Mike Moore [MSFT]
    Oct 28, 2003
  2. ani
    Replies:
    1
    Views:
    316
    Stephan Bour
    Oct 28, 2003
  3. JezB
    Replies:
    5
    Views:
    565
    Rick Spiewak
    May 26, 2004
  4. tshad
    Replies:
    5
    Views:
    434
    Scott M.
    May 13, 2005
  5. jamezw

    Session not carrying over

    jamezw, Jun 21, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    432
    Bruce Barker
    Jun 21, 2005
Loading...

Share This Page