Viewstate 隐藏字段太大,导致一切崩溃

发布于 2024-08-03 05:25:54 字数 379 浏览 6 评论 0原文

由于某种原因,我的应用程序的视图状态变得巨大(大约 1400 万个字符)。它增加了大约 1 分钟的加载时间。如果页面最终加载(这种情况并不常见),则每次有人发送表单时服务器都会崩溃,因为“帖子大小超出了允许的限制。

它突然出现。我没有添加任何字段,只是在页面上添加了一些 javascript。

人们告诉我检查视图状态分块。 Google 告诉我这样做:

<pages maxPageStateFieldLength="1024">

...所以现在我不再有一个巨大的隐藏字段,而是有 100 个非常大的隐藏字段。这不正是我想要的。

为什么.NET 会做这样的事情?我该如何解决这个问题?

For some reason the viewstate of my application became gigantic (around 14 million characters). It adds around 1 minute of loading time. If the page finally loads (which is not often), the server crashes every time someone send a form because "Post size exceeded allowed limits. "

It appeared suddenly. I didn't add any fields, just some javascript on the page.

People told me to check viewstate chunking out. Google told me to do this:

<pages maxPageStateFieldLength="1024">

... so now instead of a huge hidden field I now have something like 100 very large hidden fields. It's not exactly what I was looking for.

Why would .NET do something like this? How can I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

青柠芒果 2024-08-10 05:25:54

我建议使用实用程序来解码您的视图状态,以便您可以了解其中的实际内容(因为您显然其中有很多您似乎不需要的信息。)

A 视图状态解码器将允许您查看视图状态中您不期望的内容。然后,您可以修改代码、删除有问题的控件,或者有选择地禁用不应启用视图状态的控件(使用 EnableViewState="false" 属性)。

I would suggest using a utility to decode your viewstate so you can get an idea of what is actually within it (since you obviously have a lot of information in there you don't seem to need.)

A viewstate decoder will allow you to see what's in your viewstate that you aren't expecting. Then you can either modify your code, remove the offending control, or selectively disable viewstate (using the EnableViewState="false" attribute) for the controls that shouldn't have it enabled.

メ斷腸人バ 2024-08-10 05:25:54

请记住,控件将在没有视图状态的情况下在回发中保留其值。您通常可以禁用许多控件的视图状态,而不会出现任何问题。禁用特定控件集的视图状态:

EnableViewState="false"

如果您为所有网格和任何不需要视图状态的控件设置此选项,则会显着减小大小。

Keep in mind that controls will retain their values across postbacks without viewstate. You can often disable viewstate for a lot of your controls without any issues. To disable viewstate for a specific control set:

EnableViewState="false"

If you set this for all of your grids and any controls that you don't need viewsate for it will significantly reduce the size.

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