Reputation: 83
I'm new to asp world, and I have to keep my new job :) Switching form php to asp.net 3.5 (never used before). What would be the best practice for storing a SESSION variable in my project ?
How can I prevent my SESSION to be overwritten if my initialisation code is in the onPageLoad method of my MasterPage ?
My variables keeps beeing overwritten, please someone help me and tell me if there is any other solution than dealing with this pageLoad problem.
Upvotes: 1
Views: 1390
Reputation: 20086
You can always check that if the Session value exists or not.
if(Session["UserName"] == null)
{
Session["UserName"] = User.Identity.UserName;
}
Upvotes: 0
Reputation: 4968
First up, if your session values are getting lost... there must be something wrong. That totally defeats the purpose of having sessions!
You can try a couple of articles and get better understanding of this...
http://blogs.msdn.com/rahulso/archive/2007/01/17/troubleshooting-cookies-a-case-study.aspx
HTH
Upvotes: 1
Reputation: 3504
if(Session["account"] == null) {
Session["account"] = GetAccount();
}
Upvotes: 0