您的位置:首页 > 其它

验证视图状态 MAC 失败解决方法

2014-02-17 15:42 225 查看
验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和验证算法。不能在群集中使用

AutoGenerate。

运行时提示错误:

验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和

验证算法。不能在群集中使用 AutoGenerate。

StackTrace: 在 System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState,

String errorPageMessage, Boolean macValidationError)

在 System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)

在 System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)

在 System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState)

在 System.Web.UI.HiddenFieldPageStatePersister.Load()

在 System.Web.UI.Page.LoadPageStateFromPersistenceMedium()

在 System.Web.UI.Page.LoadAllState()

在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,

Boolean includeStagesAfterAsyncPoint)

在 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint,

Boolean includeStagesAfterAsyncPoint)

在 System.Web.UI.Page.ProcessRequest()

在 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)

在 System.Web.UI.Page.ProcessRequest(HttpContext context)

在 ASP.pcpf_login_login_aspx.ProcessRequest(HttpContext context) 位置

d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NETFiles\famsweb\d5e90b06\537ccf9e\App_Web_login.aspx.d2f46862.6plrloiq.0.cs:行号 0

在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

解决方案:

在web.config里配置

在<system.web>下添加<pages enableViewStateMac="false"></pages>

查下MSDN就明白了,validationKey和decryptionKey的默认值是AutoGenerate,由系统随机生成密钥,如果在本地或者使用的

是独立主机通常不会有什么问题,但是使用虚拟主机,一台服务器上有多个虚拟主机存在时就会出现以上问题,MSDN中也特别指出不能在群集中使用 AutoGenerate应该指定固定的密钥值,至此真相水落石出,立刻在web.config中添加关于machineKey的配置项,并手动设置其中的密钥值,这里请注意,不同加密算法对于密钥的最大字符长度是不同的,在这里能够使用的有AES,DES,3DES,SHA1,MD5,我只知道DES的密钥字符长度为16,3DES长度为48,手动设置时密钥长度必须等于其最大长度,否则会出错!至于密钥的16进制值可以随便输入。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐