视图状态超时错误 [英] Viewstate timeout error

查看:139
本文介绍了视图状态超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要是开发桌面的话,我倾向于认为是的WebForms作为Web等同的WinForms的。偏偏这是不正确的。

I develop mostly for desktop so, I tend to think as WebForms as a web equivalent of WinForms. Unfortunetly this is not true.

最近,我发现,ViewState中有某种超时。

Recently I have discovered that the Viewstate have some kind of timeout.

我的问题是类似的,因为我的大部分问题已阅读,尤其是<一个href=\"http://stackoverflow.com/questions/4348116/dynamically-adding-controls-to-asp-net-viewstate-is-not-retained-after-20-minu/5377361\">here (在我的情况是只有约5〜10分钟)。

My problem is similar as I have read in most questions, in particular here (in my case is only around 5 to 10 minutes).

<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.page.enableviewstatemac%28v=vs.110%29.aspx\"相对=nofollow>在这里中微软表示,这个问题的一个解决方案是:

Here Microsoft says that one solution for this problem is:

 <asp:Page EnableViewStateMac="False" />

不过,我们可以进一步阅读,他们说:

However as we can read further they say:

Security Note:
This attribute should never be set to false in a production Web site, 
even if the application or page does not use view state. 
The view state MAC helps ensure the security of other ASP.NET functions 
in addition to view state.

有关这个原因,我不想EnableViewStateMac设置为false,我有我的服务器无法访问(是共享的主机)。

For this reason I don't want to set EnableViewStateMac to false and I have no access to my server (is shared hosting).

我的问题是:我们可以存储ViewState的回发之间即使我们的页面停留闲置了很长一段时间?如果是的话,怎么样?

My question is: can we store the Viewstate between postbacks even if our page stay idle for a long time? If yes, how?

感谢您

推荐答案

视图状态使用机器密钥,以确保它不回发期间篡改加密。用于加密视图状态的计算机密钥默认是自动生成的,如果时间了怎么那么关键的解密将失败,因为的machineKey将得到再生。

The viewstate is encrypted using a machine key to ensure that it is not tampered with during postback. The machine key used to encrypt the viewstate is by default auto-generated and if the time out happens then the key's decryption will fail because the machinekey will get regenerated.

将machineKey是在机械设备级的配置文件可用的默认。

The machinekey is by default available at machine level config file.

<machineKey validationKey="AutoGenerate,IsolateApps"  
            decryptionKey="AutoGenerate,IsolateApps" 
            validation="SHA1" decryption="Auto" />

要解决这个问题,你可以用你自己定义的机器密钥。那么您可以使用在线工具,以及像或通过IIS。

To fix this, you can use your own defined machine key. You can generate using online tools as well, like this or through IIS.

如何添加这将machineKey到web.config文件可以在 MSDN

How to add this machinekey to web.config can be read at MSDN.

应该划归的System.Web 部分,这样的 -

It should be placed under the system.web section, like this -

<configuration>
  <system.web>
    <machineKey decryptionKey="Decryption key goes here,IsolateApps" 
                validationKey="Validation key goes here,IsolateApps" />
  </system.web>
</configuration>

这篇关于视图状态超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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