保持在ViewState的SessionPageStatePersister [英] Keeping ViewState in SessionPageStatePersister

查看:106
本文介绍了保持在ViewState的SessionPageStatePersister的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要保持一个特定的页面视图状态的会话,但以下code座不帮我,什么可能我会丢失?

因此​​,这里是code-背后我的网页文件内容;

 公共部分类ConfigurationEditorWebForm:PageBase
    {
        保护无效的Page_Load(对象发件人,EventArgs的发送)
        {
        }        保护覆盖布尔VerifyAccess()
        {
            返回true;
        }        保护覆盖PageStatePersister PageStatePersister
        {
            得到
            {
                返回新SessionPageStatePersister(本);
            }
        }
    }


解决方案

请注意,您移动页面的状态,查看状态以后,你仍然会看到在您的网页一个__ViewState元素。

另外,我认为,这种解决方案可能更正确的比别人提供的,因为它处理后退按钮多一点优雅。当存储ViewState的一个隐藏变量,它成为HTML的一部分,因此,可如果用户单击后退按钮2或3页,并与他在做什么继续。一味地捣毁ViewState中每个页面请求将prevent后退按钮的行为,从用户期望的方式。

不过,这将是不负责任的注意,这可能不是摆在首位一个伟大的想法。我建议做的至少的两件事第一:

首先,确保你已经关闭视图状态上的所有不需要它(这可能将是大多数)的控制。您可以通过设置IsViewstateEnabled假做。

二,打开HTTP COM pression您的网络服务器。即使你有一个合理规模的视图状态,总的页面权重(COM时pressed - 的不是在你的浏览器中查看的)应该是比较小的。

希望帮助!

I want to keep viewstate of a specific page in session but following code block does not help me, what might I be missing?

So here is the code-behind file content of my page;

    public partial class ConfigurationEditorWebForm : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected override bool VerifyAccess()
        {
            return true;
        }

        protected override PageStatePersister PageStatePersister
        {
            get
            {
                return new SessionPageStatePersister(this);
            }
        }
    }

解决方案

Note that even after you move the page state to view state, you will still see a __Viewstate element on your pages.

Also, I believe that this solution may be more correct than the others offered, as it handles the back button a bit more elegantly. When you store the ViewState in a hidden variable, it becomes part of the HTML, and is therefore available if the user clicks the back button 2 or 3 pages and continues with what he was doing. Blindly trashing the Viewstate with each page request will prevent the back button from behaving the way the user is expecting.

However, it would be remiss to note that this is probably not a great idea in the first place. I would suggest doing at least two things first:

First, make sure that you have turned off Viewstate on all of the controls that don't need it (which will probably be most of them). You can do this by setting 'IsViewstateEnabled' to false.

Second, turn on http compression on your webserver. Even if you have a reasonably sized viewstate, the total page weight (when compressed - not as viewed in your browser) should be relatively small.

Hope that helps!

这篇关于保持在ViewState的SessionPageStatePersister的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆