Where to save user name for entire session
-
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!
-
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!
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
-
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
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!
-
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!
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
-
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
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. 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!
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
-
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
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!
-
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!
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