无法关闭 ViewState (asp.net/VS2010),可能出了什么问题?

发布于 2025-01-08 14:37:11 字数 720 浏览 0 评论 0原文

我正在开发一个从数据库生成客户列表的应用程序。我已在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你的心境我的脸 2025-01-15 14:37:11

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

不…忘初心 2025-01-15 14:37:11

查看MSDN 文档,甚至当您禁用它时,它仍然用于检测回发:

即使EnableViewStatefalse,页面也可能包含隐藏视图
ASP.NET 使用状态字段来检测回发。

Looking at the MSDN documentation, even when you disable it, it is still used to detect postbacks:

Even if EnableViewState is false, the page might contain a hidden view
state field that is used by ASP.NET to detect a postback.

天气好吗我好吗 2025-01-15 14:37:11

您可以反序列化视图状态以查看谁在其中放入数据:

LosFormatter lf = new LosFormatter();
object deserialized = lf.Deserialize("!!! YOUR VIEWSTATE HERE !!!");

附加调试器并查看 deserialized 的内容

You can deserialize the viewstate to see who's putting data in there:

LosFormatter lf = new LosFormatter();
object deserialized = lf.Deserialize("!!! YOUR VIEWSTATE HERE !!!");

Attach a debugger and have a look at the contents of deserialized

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文