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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Where to save user name for entire session

Where to save user name for entire session

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netcomsecuritytools
8 Posts 3 Posters 2 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.
  • L Offline
    L Offline
    Luis Alonso Ramos
    wrote on last edited by
    #1

    Hello, I'm building an ASP.NET app (my first and I like it!) with Forms authentication. When the session starts, I want to save the username and his name (luisr and Luis, for example) in the Session object. Where is the appropiate place to do it? I was thinking on doing it when the Login button is clicked and the user authenticated in my Login form, but it won't get called when the "Remember me" check box was checked. What do you think? -- LuisR


    Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

    C 1 Reply Last reply
    0
    • L Luis Alonso Ramos

      Hello, I'm building an ASP.NET app (my first and I like it!) with Forms authentication. When the session starts, I want to save the username and his name (luisr and Luis, for example) in the Session object. Where is the appropiate place to do it? I was thinking on doing it when the Login button is clicked and the user authenticated in my Login form, but it won't get called when the "Remember me" check box was checked. What do you think? -- LuisR


      Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

      C Offline
      C Offline
      colin mcadam
      wrote on last edited by
      #2

      Sounds perfect to me Once the user is authenticated do your Session.Add bit I do this for a login page and use the username many times later in the app and it works well for me Colin

      L 1 Reply Last reply
      0
      • C colin mcadam

        Sounds perfect to me Once the user is authenticated do your Session.Add bit I do this for a login page and use the username many times later in the app and it works well for me Colin

        L Offline
        L Offline
        Luis Alonso Ramos
        wrote on last edited by
        #3

        But what if the user is authenticated without going to the login page (Rember Me or persitent cookie)? Where do I call Session.Add? -- LuisR


        Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

        R 1 Reply Last reply
        0
        • L Luis Alonso Ramos

          But what if the user is authenticated without going to the login page (Rember Me or persitent cookie)? Where do I call Session.Add? -- LuisR


          Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

          R Offline
          R Offline
          R Senthil Kumaran
          wrote on last edited by
          #4

          actually its not required to save the username in the forms authentication coz the user.Identity will tell u the username from the formsauthentication class so need not save it!! persistant cookie is when the page is getting loaded u need to check for the cookie name that was created by the Forms authentication and from that cast it to sting and check it then authenticate the user for the page!!:) Loving Code, R. Senthil Kumaran

          L 1 Reply Last reply
          0
          • R R Senthil Kumaran

            actually its not required to save the username in the forms authentication coz the user.Identity will tell u the username from the formsauthentication class so need not save it!! persistant cookie is when the page is getting loaded u need to check for the cookie name that was created by the Forms authentication and from that cast it to sting and check it then authenticate the user for the page!!:) Loving Code, R. Senthil Kumaran

            L Offline
            L Offline
            Luis Alonso Ramos
            wrote on last edited by
            #5

            R. Senthil Kumaran wrote: the user.Identity will tell u the username Yes, I found that, and that's what I'm currently using. But I'd like to save other data, such as the user database ID, and his first name (to personalize the page) and I don't want to get that from the database everytime. Thanks! -- LuisR


            Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

            R 1 Reply Last reply
            0
            • L Luis Alonso Ramos

              R. Senthil Kumaran wrote: the user.Identity will tell u the username Yes, I found that, and that's what I'm currently using. But I'd like to save other data, such as the user database ID, and his first name (to personalize the page) and I don't want to get that from the database everytime. Thanks! -- LuisR


              Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

              R Offline
              R Offline
              R Senthil Kumaran
              wrote on last edited by
              #6

              That u can do before authenticating the user if the user is authenticated u will be redirecting him to the next page so, b4 redirecting just put the db ID in the sesssion and have it redirected... This is the best Solution that most of the devlpr will do... Loving Code, R. Senthil Kumaran

              L 1 Reply Last reply
              0
              • R R Senthil Kumaran

                That u can do before authenticating the user if the user is authenticated u will be redirecting him to the next page so, b4 redirecting just put the db ID in the sesssion and have it redirected... This is the best Solution that most of the devlpr will do... Loving Code, R. Senthil Kumaran

                L Offline
                L Offline
                Luis Alonso Ramos
                wrote on last edited by
                #7

                I tried calling Session.Add in Application_AuthenticateRequest (always called, whether Login page or not) and an exception was thrown about something like session state not being available there. I know I could do it in my Login form, before redirecting, but if the "Remember me" persistent cookie exists, my user will never get to the login page. -- LuisR


                Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

                R 1 Reply Last reply
                0
                • L Luis Alonso Ramos

                  I tried calling Session.Add in Application_AuthenticateRequest (always called, whether Login page or not) and an exception was thrown about something like session state not being available there. I know I could do it in my Login form, before redirecting, but if the "Remember me" persistent cookie exists, my user will never get to the login page. -- LuisR


                  Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

                  R Offline
                  R Offline
                  R Senthil Kumaran
                  wrote on last edited by
                  #8

                  yeah thats fine have a method in ur BU layer which checks fof the exsistance of the authcookie and if it is there from there query your databse and take the db id and put in the session call this method in the pages that requires authentication note: have this in the intializecomponent method of the page!! and not in pageload!! i will try is ther any other option on your question and let u know!! Loving Code, R. Senthil Kumaran

                  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