Determine size of ASP.NET page's viewstate before serving page

前端 未结 3 1715
失恋的感觉
失恋的感觉 2020-12-21 01:13

What ASP.NET page lifecycle event can I write code in to determine the size of the viewstate that being sent out? Also, is it possible to determine the size without parsing

3条回答
  •  长情又很酷
    2020-12-21 01:40

    You can go on the function that is going to writing the viewstate, the SavePageStateToPersistenceMedium. This is the function that also used to compress viewstate...

    For example...

    public abstract class BasePage : System.Web.UI.Page
    {
        private ObjectStateFormatter _formatter = new ObjectStateFormatter();
    
        protected override void SavePageStateToPersistenceMedium(object viewState)
        {
            MemoryStream ms = new MemoryStream();    
            _formatter.Serialize(ms, viewState);    
            byte[] viewStateArray = ms.ToArray();
    
            ....
    
        }
    }
    

    Some reference.
    http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx
    http://forums.asp.net/p/1139883/3836512.aspx
    http://www.dotnetcurry.com/ShowArticle.aspx?ID=67&AspxAutoDetectCookieSupport=1

提交回复
热议问题