AntiForgeryToken 和 MachineKey 配置

发布于 2024-11-19 11:36:09 字数 616 浏览 2 评论 0原文

我正在尝试将 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一绘本一梦想 2024-11-26 11:36:09

我终于想通了。我做了更多的谷歌搜索,发现如果我不清除浏览器上的缓存,它将保留无效的视图状态。显然,除非所有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文