asp.net-mvc - 防伪异常 : A required anti-forgery token was not supplied or was invalid

标签 asp.net-mvc antiforgerytoken

我有一个 MVC2 应用程序。我正在尝试实现 AntiForgeryToken 帮助程序来防止 CSRF 攻击。

我正在使用 Steve Sanderson 的博客实现这一点:http://blog.stevensanderson.com/2008/09/01/prevent-cross-site-request-forgery-csrf-using-aspnet-mvcs-antiforgerytoken-helper/

当我在新的 MVC2 项目中实现它时,它可以工作。但是当我把它放在我的真实应用程序中时,它总是抛出这个异常:
所需的防伪 token 未提供或无效。

这是我的 Controller 代码:

[ValidateAntiForgeryToken]
public ActionResult SubmitUpdate()
{

    // Something goes here
    return View();
}

View 中的代码:
<% using (Html.BeginForm("SubmitUpdate", "Test"))
   {%>
   <%= Html.AntiForgeryToken() %>
       <input type="submit" value="Submit" />
<% } %>

除了实际应用使用 ADFS 进行身份验证外,这两个应用没有任何区别。我错过了什么?任何帮助将不胜感激。谢谢!

最佳答案

您是否尝试删除 cookie 并重试?

关于asp.net-mvc - 防伪异常 : A required anti-forgery token was not supplied or was invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6792435/

相关文章:

c# - 防伪 token 可重复使用

asp.net-mvc - 在 ASP.NET MVC 3 中覆盖基本 View 模型的属性

javascript - 使用jquery隐藏html元素后RequestVerificationToken值为空

jquery - 带有 CORS 预检选项请求的 Ajax 防伪 POST(302 重定向)

c# - 当前上下文中不存在名称 'AntiForgery'

asp.net-mvc - 有没有办法重命名 RequestVerificationToken cookie 名称?

c# - DevOps for ASP.NET MVC : Running a web. 在构建和打包后,在单独的步骤中进行配置转换

c# - CaSTLe Windsor 在程序集中找不到安装程序

asp.net-mvc - 比较两个 RouteValueDictionary 实例

jquery - 使用 ASP.NET MVC Url.Action 在 JQuery 中生成链接