M
MattC
Hi,
I am persisting the viewstate for each page into the Cache object, below is
shown my methods for saving and loading:
I am able to save the viewstate to the cache and most times I can load it
ok, however it seems that every now and again it fails to Deserialize the
viewstate.
My Application pool is set to shutdown after 180mins of idle.
IIS6.0 W2K3 SVR
TIA
MattC
private string ViewStateCacheKey
{
get{ return "VIEWSTATE_" + Request.UserHostAddress; }
}
protected override void SavePageStateToPersistenceMedium(object viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.Serialize(oStringWriter, viewState);
string str = this.ViewStateCacheKey + "_" + Guid.NewGuid().ToString();
try
{
Cache.Insert(str, //key
oStringWriter.ToString(), //value
null, //dependency
Cache.NoAbsoluteExpiration, //no absolute expiration
new TimeSpan(0,0,Session.Timeout + 10,0,0), //sliding expiration
Seesion timeout
CacheItemPriority.High,
onRemove); //call back on removal
}
catch(Exception e)
{
throw new Exception("Failed to store viewstate in Cache", e);
}
}
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", String.Empty);
}
protected override object LoadPageStateFromPersistenceMedium()
{
object viewstate = null;//return viewstate
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KEY"];
try
{
viewstate = oLosFormatter.Deserialize(Cache[str].ToString());//cache
}
catch(Exception e)
{
Events.WriteToLog("Failed to deserialize ViewState '" + str +"'
from cache: " + e.Message);//system event log
}
return viewstate;
}
I am persisting the viewstate for each page into the Cache object, below is
shown my methods for saving and loading:
I am able to save the viewstate to the cache and most times I can load it
ok, however it seems that every now and again it fails to Deserialize the
viewstate.
My Application pool is set to shutdown after 180mins of idle.
IIS6.0 W2K3 SVR
TIA
MattC
private string ViewStateCacheKey
{
get{ return "VIEWSTATE_" + Request.UserHostAddress; }
}
protected override void SavePageStateToPersistenceMedium(object viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.Serialize(oStringWriter, viewState);
string str = this.ViewStateCacheKey + "_" + Guid.NewGuid().ToString();
try
{
Cache.Insert(str, //key
oStringWriter.ToString(), //value
null, //dependency
Cache.NoAbsoluteExpiration, //no absolute expiration
new TimeSpan(0,0,Session.Timeout + 10,0,0), //sliding expiration
Seesion timeout
CacheItemPriority.High,
onRemove); //call back on removal
}
catch(Exception e)
{
throw new Exception("Failed to store viewstate in Cache", e);
}
}
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", String.Empty);
}
protected override object LoadPageStateFromPersistenceMedium()
{
object viewstate = null;//return viewstate
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KEY"];
try
{
viewstate = oLosFormatter.Deserialize(Cache[str].ToString());//cache
}
catch(Exception e)
{
Events.WriteToLog("Failed to deserialize ViewState '" + str +"'
from cache: " + e.Message);//system event log
}
return viewstate;
}