Skip to content

Instantly share code, notes, and snippets.

@mpj
Created February 2, 2010 12:56
Show Gist options
  • Save mpj/292641 to your computer and use it in GitHub Desktop.
Save mpj/292641 to your computer and use it in GitHub Desktop.
protected override void SavePageStateToPersistenceMedium(object viewState)
{
if (Page.ToString() == "ASP.default_aspx")
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" + DateTime.Now.Ticks.ToString();
Session[str] = viewState; // session works in web garden
//Cache.Add(str, viewState, null, DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero,
//CacheItemPriority.Default, null);
ClientScript.RegisterHiddenField("__VIEWSTATE_KEY", str);
ClientScript.RegisterHiddenField("__VIEWSTATE", "");
}
else
{
base.SavePageStateToPersistenceMedium(viewState);
}
}
protected override object LoadPageStateFromPersistenceMedium()
{
if (Page.ToString() == "ASP.default_aspx")
{
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid viewstate key:" + str);
}
return Session[str];
}
else
{
return base.LoadPageStateFromPersistenceMedium();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment