Determine ASP.NET Page View Window Size Before Page Display

In which ASP.NET page lifecycle event can I write code to determine the size of the submitted watchlist? In addition, is it possible to determine the size indiscriminately through the rendered HTML (for example, a property on the page object) or analyze the only way?

What I would like to do is record sizes, especially if they cross a certain threshold.

+5
source share
3 answers

You can go to the function that will write to viewstate, SavePageStateToPersistenceMedium . This is a function that is also used to compress viewstate ...

For instance...

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();

        ....

    }
}

.
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

+4

SaveStateCompleted, , viewstate. , ToString .

ViewState.ToString.Count() 
0

, Reflector'd , viewstate, HttpModule, , , , .

I say this because you will need to get a literal string from the page after it has been rendered, which will not happen until all user-defined events are triggered. See Reflector Output below (partial):

            this.PerformPreRenderComplete();
            if (context.TraceIsEnabled)
            {
                this.Trace.Write("aspx.page", "End PreRenderComplete");
            }
            if (context.TraceIsEnabled)
            {
                this.BuildPageProfileTree(this.EnableViewState);
                this.Trace.Write("aspx.page", "Begin SaveState");
            }
            if (EtwTrace.IsTraceEnabled(5, 4))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_SAVE_VIEWSTATE_ENTER, this._context.WorkerRequest);
            }
            this.SaveAllState();
            if (EtwTrace.IsTraceEnabled(5, 4))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_SAVE_VIEWSTATE_LEAVE, this._context.WorkerRequest);
            }
            if (context.TraceIsEnabled)
            {
                this.Trace.Write("aspx.page", "End SaveState");
                this.Trace.Write("aspx.page", "Begin SaveStateComplete");
            }
            this.OnSaveStateComplete(EventArgs.Empty);
            if (context.TraceIsEnabled)
            {
                this.Trace.Write("aspx.page", "End SaveStateComplete");
                this.Trace.Write("aspx.page", "Begin Render");
            }
            if (EtwTrace.IsTraceEnabled(5, 4))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_RENDER_ENTER, this._context.WorkerRequest);
            }
            if (str != null)
            {
                this.ExportWebPart(str);
            }
            else
            {
                this.RenderControl(this.CreateHtmlTextWriter(this.Response.Output));
            }
            if (EtwTrace.IsTraceEnabled(5, 4))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_RENDER_LEAVE, this._context.WorkerRequest);
            }
            if (context.TraceIsEnabled)
            {
                this.Trace.Write("aspx.page", "End Render");
            }
            this.CheckRemainingAsyncTasks(false);

Otherwise, you can grab the viewstatebag and iterate over its contents. This also works well, depending on how many parts you want to insert.

0
source

All Articles