C# ViewState 仅在 Safari 中无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ViewState invalid only in Safari
提问by Anthony Main
One of the sites I maintain relies heavily on the use of ViewState
(it isn't my code). However, on certain pages where the ViewState
is extra-bloated, Safari throws a "Validation of viewstate MAC failed"
error.
我维护的网站之一在很大程度上依赖于使用ViewState
(这不是我的代码)。但是,在某些ViewState
特别臃肿的页面上,Safari 会抛出"Validation of viewstate MAC failed"
错误。
This appears to only happen in Safari. Firefox, IE and Opera all load successfully in the same scenario.
这似乎只发生在 Safari 中。Firefox、IE 和 Opera 都在同一场景中成功加载。
采纳答案by Anthony Main
I've been doing a little research into this and whilst I'm not entirely sure its the cause I believe it is because Safari is not returning the full result set (hence cropping it).
我一直在对此进行一些研究,虽然我不完全确定它的原因,但我相信这是因为 Safari 没有返回完整的结果集(因此对其进行了裁剪)。
I have been in dicussion with another developer and found the following post on Channel 9 as well which recommends making use of the SQL State service to store the viewstate avoiding the postback issue and also page size.
我一直在与另一位开发人员讨论,并在 Channel 9 上发现了以下帖子,其中建议使用 SQL 状态服务来存储视图状态,避免回发问题和页面大小。
Does this seem like the best solution?
这似乎是最好的解决方案吗?
回答by tags2k
My first port of call would be to go through the elements on the page and see which controls:
我的第一个停靠点是浏览页面上的元素并查看哪些控件:
- Will still work when I switch ViewState off
- Can be moved out of the page and into an AJAX call to be loaded when required
- 当我关闭 ViewState 时仍然可以工作
- 可以移出页面并在需要时加载到 AJAX 调用中
Failing that, and here's the disclaimer - I've never used this solution on a web-facing site - but in the past where I've wanted to eliminate massive ViewStates in limited-audience applications I have stored the ViewState in the Session.
如果失败了,这里是免责声明 - 我从未在面向 Web 的站点上使用过这个解决方案 - 但在过去,我想在有限的受众应用程序中消除大量的 ViewState,我将 ViewState 存储在 Session 中。
It has worked for me because the hit to memory isn't significant for the number of users, but if you're running a fairly popular site I wouldn't recommend this approach. However, if the Session solution works for Safari you could always detect the user agent and fudge appropriately.
它对我有用,因为对内存的影响对于用户数量来说并不重要,但是如果您正在运行一个相当受欢迎的站点,我不会推荐这种方法。但是,如果 Session 解决方案适用于 Safari,您总是可以检测到用户代理并进行适当的捏造。
回答by Rob Allen
While I second the Channel 9 solution, also be aware that in some hosted environments Safari is not considered an up-level browser. You may need to add it to your application's browscap in order to make use of some ASP.Net features.
虽然我支持 Channel 9 解决方案,但请注意,在某些托管环境中,Safari 不被视为高级浏览器。您可能需要将其添加到应用程序的浏览器中,以便使用某些 ASP.Net 功能。
That was the root cause of some headaches we had for a client's site that used the ASP Menu control.
这就是我们为使用 ASP 菜单控件的客户站点带来的一些麻烦的根本原因。