Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How can I keep user permissions and info available across multiple classes? [modified]

How can I keep user permissions and info available across multiple classes? [modified]

Scheduled Pinned Locked Moved C#
questioncsharpdatabasehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jacobus01
    wrote on last edited by
    #1

    I need to keep a logged in user's details and permissions kept in a globally accessible object.I know that c# doesn't allow you to store an object that is globally accessible but is it then better to just retrieve a users permissions and details again from the db instead of just passing a reference to every new form that I create? This object will be used to determine if a user can enter a sub-system of the application or just to change his password. Should I use MDI Forms perhaps? Any help would be greatly appreciated. thanx in advance

    modified on Tuesday, May 19, 2009 3:34 AM

    R 1 Reply Last reply
    0
    • J Jacobus01

      I need to keep a logged in user's details and permissions kept in a globally accessible object.I know that c# doesn't allow you to store an object that is globally accessible but is it then better to just retrieve a users permissions and details again from the db instead of just passing a reference to every new form that I create? This object will be used to determine if a user can enter a sub-system of the application or just to change his password. Should I use MDI Forms perhaps? Any help would be greatly appreciated. thanx in advance

      modified on Tuesday, May 19, 2009 3:34 AM

      R Offline
      R Offline
      riced
      wrote on last edited by
      #2

      Possibly use a static class? E.g.

      public static class UserDetails
      {
      public static string name;
      public static string dob;
      }

      On start up the app could then do something like UserDetails.name = nameFromSomewhere Elsewhere you could use e.g. if (UserDetails.name == "Fred")... You would probably want to use properties rather than public fields. :)

      Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

      J 1 Reply Last reply
      0
      • R riced

        Possibly use a static class? E.g.

        public static class UserDetails
        {
        public static string name;
        public static string dob;
        }

        On start up the app could then do something like UserDetails.name = nameFromSomewhere Elsewhere you could use e.g. if (UserDetails.name == "Fred")... You would probably want to use properties rather than public fields. :)

        Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

        J Offline
        J Offline
        Jacobus01
        wrote on last edited by
        #3

        Simple, yet effective. Thanx. I kept on thinking that I'd have to instantiate an object for this purpose. I even considered running a new thread and just keep the details in an object referenced by that thread. But a static class seems simpler. Regards

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups