设置ViewStateUserKey让我一个" MAC视图状态验证不合格"错误 [英] Setting ViewStateUserKey gives me a "Validation of viewstate MAC failed" error
问题描述
我在的BasePage $ C C>类,我所有的ASPX页面从推导出以下内容:
I have the following in my BasePage
class which all my ASPX pages derive from:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
ViewStateUserKey = Session.SessionID;
}
我也有的Web.config
A 的machineKey
设置。我不认为这个错误是因为Web场,因为出现这种情况我开发的机器上了。
I also have a machineKey
set in Web.config
. I don't think this error is because of a web farm because this happens on my dev machine too.
我的主机现在已经升级到.NET 3.5 SP1。此更新后,每次我与 ViewStateUserKey
设置上面,我不断地得到编译验证视图状态MAC失败错误在每次回发。
My host has now upgraded to .NET 3.5 SP1. After this update, everytime I compile with the ViewStateUserKey
setting above, I constantly get the "Validation of viewstate MAC failed" error on every postback.
我在做什么错在这里?这是设置甚至必要再与最新的框架更新?
What am I doing wrong here? Is this setting even necessary anymore with the latest framework update?
推荐答案
确定 - 林晚了一年的谈话 - 但这是如何正确的答案?这仅适用于通过验证的用户的情况下,并使用 ViewStateUserKey
作为用户名是一个容易得多比会话ID GUID猜测。
OK - Im a year late to the conversation - but how is this the correct answer? This applies only in the case of authenticated users and using the ViewStateUserKey
as the username is a lot easier to guess than a session id GUID.
顺便说一句,如果你想'修复'的code向上顶,使用Session ID,但你必须设置一个会话变量,以使会话ID更改每次停下来。防爆。会话[任何东西] = DateTime.Now
BTW if you want to 'fix' the code up top, use the Session ID, however you must set a session variable in order for the session id to stop from changing every time. Ex.
Session["Anything"] = DateTime.Now
ViewStateUserKey = Session.SessionID;
这当然是假设你要使用会话,否则,你需要一些其他的键使用,比如用户名或任何其他GUID保存在cookie中。
This of course is assuming you are going to use sessions, otherwise you need some other key to use such as the username or any other guid kept in a cookie.
这篇关于设置ViewStateUserKey让我一个" MAC视图状态验证不合格"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!