RE: How and why to save ViewState in a session object



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
.



Relevant Pages

  • Re: ViewState, Application, Session....
    ... viewstate and as a part of Request pipeline the framework initializes the ... Session: Session is a storage area that is specific to one user. ... there are times when session provides a good way to store user specific ... Application or Cache: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to store a datatable temporarily
    ... Cache - Application caching ... If you are paging small amounts of data, you can either pull it each trip or cache in ViewState. ... Once you start getting more data, you will want to use Cache or Session. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: How and why to save ViewState in a session object
    ... Cache is a more efficient way of persisting data on the server side. ... of the items that are stored in the cache (which will not happen when session ... Cache.Add(_vskey, viewState, null, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Cache, Session, ViewState and Application
    ... My question is to do with scalability and the location for storate of cache, ... Session - Data is stored in memory ... ViewState - Page (but can be modified to overwrite the storage mechanism to ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: how to resume a sleeping thread
    ... For every request that it gets it will span a new ... till it gets the response. ... Given a pointer to a session object and the knowledge ... awaken a worker to handle it. ...
    (comp.programming.threads)