NET页面的ViewState的大小

NET页面的ViewState的大小

本文介绍了服务页面之前确定ASP.NET页面的ViewState的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么ASP.NET页面生命周期事件我可以写$ C $中C到确定所发出的视图状态的大小?此外,是有可能的大小来确定,而无需通过呈现的HTML解析(如页面对象上的属性),或者是解析的唯一途径?

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 through the rendered HTML (like a property on the page object) or is parsing the only way?

我想要做的是记录大小,特别是如果他们越过某一阈值。

What I'd like to do is log the sizes, specifically if they cross a certain threshold.

推荐答案

您可以去上是要编写视图状态,在 SavePageStateToPersistenceMedium功能即可。这是也可用于COM preSS视图状态的功能...

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...

例如...

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

        ....

    }
}

一些参考。结果
结果
结果

这篇关于服务页面之前确定ASP.NET页面的ViewState的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 05:54