You may have some pages which are being penalized by certain search engines due to the size of the viewstate embedded in the page. You can move the viewstate into the session easily by overriding the following methods:
void SavePageStateToPersistenceMedium(object viewstate)
object LoadPageStateFromPersistenceMedium()
I recommend you override these methods in a base page class of some kind so that you can just inherit your page from it. The code I have used in the past is below:
using System;
using System.Data;
using System.IO;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class MyBasePage : Page
{
public MyBasePage()
{
}
private LosFormatter _LosFormatter;
protected override void SavePageStateToPersistenceMedium(object viewState)
{
string Key = Request.Url.ToString() + "__VIEWSTATE";
System.IO.MemoryStream memStream = new System.IO.MemoryStream();
_LosFormatter.Serialize(memStream, viewState);
memStream.Flush();
Session[Key] = memStream;
}
protected override object LoadPageStateFromPersistenceMedium()
{
string Key = Request.Url.ToString() + "__VIEWSTATE";
if (Session[Key] != null)
{
System.IO.MemoryStream memStream = (System.IO.MemoryStream)Session[Key];
memStream.Seek(0, SeekOrigin.Begin);
return (object)_LosFormatter.Deserialize(memStream);
}
return null;
}
}
No comments yet... Be the first to leave a reply!