Reputation: 20348
I an using Session for storing UserName for whole project. But it always time out before 20 min. I want set value in properties and want to use in project but when my page is loading again its showing null value.
How can i save this value in this?
Code what i am using.
public string UserName {get; set; }
public string Password {get; set;}
Upvotes: 0
Views: 116
Reputation: 39283
With a public string UserName {get; set;}
you don't set anything in the Session.
Use this instead:
public string UserName
{
get { return Session["UserName"] as string; }
set { Session["UserName"] = value; }
}
Upvotes: 0
Reputation: 190943
Properties are a language construct (not an ASP.NET feature) and won't survive either.
You should persist the information in a database or up the session timeout.
Upvotes: 3