- Across Multiple Page.
- Saved in a specific session, cleared when the session dies (usually after 20 minutes of inactivity).
- Saved in Server.
- valid for any type of objects.
public List<Contact> SessionContacts
{
get { return (List<Contact>)HttpContext.Current.Session["SessionConacts"]; }
set { HttpContext.Current.Session["SessionConacts"] = value; }
}
View State
- Only that web page.
- It is stored in a hidden field.
- Saved in page, travels up and down between client and server.
- No expiration date.
- Valid for Serializable data only.
public List<Contact> SessionContacts
{
get { return (List<Contact>)ViewState["VSConacts"]; }
set { ViewState["VSConacts"] = value; }
}
Conclusion
If data you store in the view state is not large enough to cause slow performance , use view state.
If you store too much data in session and you create many sessions in a short period with many of your concurrent users, you would be killing your server.
No comments:
Post a Comment