RE: How and why to save ViewState in a session object
- From: AAOMTim <AAOMTim@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 21 Aug 2006 12:21:02 -0700
Thank you for your response. Can you discuss the merits of saving to a Cache
object instead of to a Session?
--
Tim
"Augustin Prasanna" wrote:
Hi Tim,.
View State can be customized to be stored in a Session or Cache object. It
is done by overriding the 'SavePageStateToPersistenceMedium' and
'LoadPageStateFromPersistenceMedium' methods. (see code snippet below)
protected override void SavePageStateToPersistenceMedium(Object viewState)
{
string _vskey;
_vskey = "VIEWSTATE_" + base.Session.SessionID + "_" + Request.RawUrl +
"_" + System.DateTime.Now.Ticks.ToString();
Cache.Add(_vskey, viewState, null,
System.DateTime.Now.AddMinutes(Session.Timeout), Cache.NoSlidingExpiration,
CacheItemPriority.Default, null);
RegisterHiddenField("_VIEWSTATE_KEY", _vskey);
}
protected override object LoadPageStateFromPersistenceMedium()
{
string _vskey = Request.Form["_VIEWSTATE_KEY"];
if (_vskey == null)
{
return null;
}
else
{
return Cache[_vskey];
}
}
Advantages: If the ViewState is large, it increases the page size
considerably and results in an increase in response time (page load time).
Saving the ViewState to a session/cache can result in an improved response
time (page size is reduced considerably). On the other hand, it can consume
server resources (which can be handled by improving the hardware).
Regards,
Augustin
"AAOMTim" wrote:
I have a large ViewState and I've heard I can save the ViewState in a sesison
object. What are the advantages of doing so and how do I do it? I've been
told that I am gettign DNS timeouts because of the ViewState being too large.
I'm trying to avoid writing manual paging routines for now.
--
Tim
- Follow-Ups:
- RE: How and why to save ViewState in a session object
- From: Augustin Prasanna
- RE: How and why to save ViewState in a session object
- References:
- RE: How and why to save ViewState in a session object
- From: Augustin Prasanna
- RE: How and why to save ViewState in a session object
- Prev by Date: Re: LISTBOX : how to insert VBTab or Blank spaces ?
- Next by Date: Re: VBScript causing problems
- Previous by thread: RE: How and why to save ViewState in a session object
- Next by thread: RE: How and why to save ViewState in a session object
- Index(es):
Relevant Pages
|