无法关闭 ViewState (asp.net/VS2010),可能出了什么问题?
我正在开发一个从数据库生成客户列表的应用程序。我已在 default.aspx 中禁用了 ViewState,但现在当我查看生成的 HTML 页面的源代码时,我看到 ViewState 已打开。
我尝试添加 ViewStateMode="Disabled" 和 EnableViewState="False" (单独甚至一起),但没有任何运气。
有什么问题吗?
源代码中的 ViewState 代码(如果有帮助):
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="88luWaDvrTt0+OWLhB and a lots of characters after this...
编辑:现在,当我再次查看源代码时,我可以看到以下内容,我觉得很奇怪:
- 有很多 ViewState 字符(需要 15-20 秒才能滚动)
- 有两个具有 ViewState 代码的地方,彼此分开
I'm working on an application which generates a list of customers from a db. I have disabled ViewState in default.aspx, but now when I viewed the source code of the generated HTML page I saw that the ViewState is on.
I've tried to add both ViewStateMode="Disabled" and EnableViewState="False" (separately and even together) without any luck.
What can be wrong?
ViewState code from the source code if it helps:
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="88luWaDvrTt0+OWLhB and a lots of characters after this...
EDIT: Now when I looked again in the source code I can see the following which I find strange:
- There's A LOT of ViewState characters (takes 15-20 seconds to scroll through it)
- There's two places with ViewState code, separate from each other
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ASP.Net 页面同时具有控制状态和视图状态。控制状态用于绝对关键的数据,没有这些数据控件就无法运行(至少在理论上)。
视图状态和控制状态都存储在同一字段中。视图状态完全禁用的站点可能仍具有控制状态。
不幸的是,ASP.Net 在如何区分两者方面非常不一致。例如,在禁用视图状态的情况下,
DropDownList
将不再触发更改事件。我认为这是下拉菜单的关键功能,我很乐意花费几个字节的空间来存储控制状态中当前选定的值,以便可以检测到更改。如果您想知道包含状态的隐藏字段的内容,您可以解码它 。它对于检测视图状态“泄漏”非常有用。
ASP.Net pages have both Control State and View State. Control State is for absolutely critical data that the control can't function without (at least in theory).
View State and Control State are both stored in the same field. A site with View State completely disabled may still have Control State.
Unfortunately, ASP.Net is quite inconsistent as to how it differentiates between the two. For example, a
DropDownList
will no longer fire change events with View State disabled. I consider that a critical function of a drop down and I would be happy to spend the few bytes of space to store the currently selected value in Control State so that a change could be detected.If you are wondering about the contents of the hidden field containing state, you can decode it. It can be very useful for detecting View State "leaks".
查看MSDN 文档,甚至当您禁用它时,它仍然用于检测回发:
Looking at the MSDN documentation, even when you disable it, it is still used to detect postbacks:
您可以反序列化视图状态以查看谁在其中放入数据:
附加调试器并查看
deserialized
的内容You can deserialize the viewstate to see who's putting data in there:
Attach a debugger and have a look at the contents of
deserialized