g_r_a_robinson Posted March 9, 2004 Posted March 9, 2004 I am looking to use maybe 8 session variables that will be modified from time to time during the time a user is logged on. At the moment the session var is created on a need to use basis. IE I only create one whenever a user access parts of the app where its required to remember certain things the user has selected. My question is this. Is it bad practice to have sessions created willy nilly, on the fly like this? And if so would be going along the right lines to have all of my session vars created in one place? Maybe in the Global.asax file? Or after succesful login. The reason I ask is that i want all of my session vars to be in one place so that I can destroy them all in place when the time comes. I just want to do this right and the way it should be done. But i've searched hi and lo to find some kind of standard or model for this kind of thing. Thanks a newbie. Quote
eramgarden Posted March 9, 2004 Posted March 9, 2004 See if this link helps: http://alpha.oreillynet.com/pub/a/dotnet/2003/03/24/sessionstate.html Quote
g_r_a_robinson Posted March 9, 2004 Author Posted March 9, 2004 Thanks for that but it didn't really address my question. Quote
AdrenalineX Posted March 9, 2004 Posted March 9, 2004 I believe that a Session Object is created by default in a .NET Web Application whether you use utilize it or not. Having 8 variables with values assigned the whole length of the user's session isn't going to affect your application unless this is a very traffic-intensive site. Accessing the object in different locations (whether it be assigning or retrieving values) won't be an issue and isn't poor practice unless you are looping through the object instead of directly accessing each variable. As far as destroying the Session Object, I believe that the object will actually persist until the session itself is terminated. You can simply deallocate the variables with a Session.Abandon() call from anywhere within the application. Hope this helps, AdrenalineX Quote
Moderators Robby Posted March 9, 2004 Moderators Posted March 9, 2004 g_r_a_robinson, your approach of creating them only as needed is the best approach, why create one if it won't be used. And if there are objects that may be used by other clients such as States in a Dropdown then consider using the Cache instead. Quote Visit...Bassic Software
kahlua001 Posted March 9, 2004 Posted March 9, 2004 Session.Abandon will kill the user's session, it'll just be recreated again. If you want to remove items from the user's sesesion, use Session.remove. It also depends on what you put into these session variables, 8 might not seem alot, but if you put datasets into them, then you have 100 ppl on your site and your site is on a shared server....think about moving the session management out of process, perhaps into a windows service or a db. There was a discussion about sessions not too long ago. i'll try to find it add the link. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.