AntiForgeryToken 和 MachineKey 配置
我正在尝试将 .NET MVC 应用程序部署到 GoDaddy 服务器。我的一个页面上有一个 Html.AntiForgeryToken ,导致每次点击它时都会抛出异常。
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
我已经使用以下 URL 生成了机器密钥
http://aspnetresources.com/tools/machineKey
,并将页面 viewStateEncryptionMode 设置为“始终”,
<pages viewStateEncryptionMode="Always">
但我仍然收到错误,并且不知道下一步该怎么做。任何建议将不胜感激。
I am trying to deploy a .NET MVC application to GoDaddy servers. I have an Html.AntiForgeryToken on one of my pages that is causing it throw an exception every time I hit it.
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
I have generated a machine key using the following URL
http://aspnetresources.com/tools/machineKey
and have set the pages viewStateEncryptionMode to "Always"
<pages viewStateEncryptionMode="Always">
I am still receiving the error however and am at a lost as to what to do next. Any suggestions would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于想通了。我做了更多的谷歌搜索,发现如果我不清除浏览器上的缓存,它将保留无效的视图状态。显然,除非所有 chrome 浏览器窗口都关闭(我使用很多 chrome 浏览器),否则 chrome 会在每个连续浏览器中保留某种视图状态,即使缓存已被清除。
我发现该代码可以在 Firefox 和 IE 中尝试,并且成功了。然后我关闭了所有 Chrome 窗口(清除缓存后)并重新启动。然后,我能够成功导航到带有 AntiForgeryToken 的页面。
I finally figured it out. I did a little bit more google searching and found that if I don't clear the cache on the browser it will retain the invalid viewstate. Apparently chrome holds onto some semblance of the viewstate in each consecutive browser unless all of the chrome browser windows are closed down (I use alot of chrome browsers), even when the cache has been cleared.
I found that the code worked by trying it in Firefox and IE which was successful. I then closed down all of the chrome windows (after clearing cache) and restarted. I was then able to navigate successfully to the page with the AntiForgeryToken on it.