0

我在 .Net 4 和 IIS6(Win2003 服务器)上运行 MVC3 Web 应用程序。我们可以间歇性地捕获以下错误消息:

System.ArgumentException: Value cannot be null or an empty string.
Parameter name: serializedToken
   at System.Web.Helpers.AntiForgeryDataSerializer.Deserialize(String serializedToken)
   at System.Web.Helpers.AntiForgeryWorker.GetAntiForgeryTokenAndSetCookie(HttpContextBase httpContext, String salt, String domain, String path)
   at System.Web.Helpers.AntiForgeryWorker.GetHtml(HttpContextBase httpContext, String salt, String domain, String path)
   at System.Web.Helpers.AntiForgery.GetHtml(HttpContextBase httpContext, String salt, String domain, String path)
   at System.Web.Mvc.HtmlHelper.AntiForgeryToken(String salt, String domain, String path)
   at System.Web.Mvc.HtmlHelper.AntiForgeryToken()
   at ASP._Page_Views_Introduction_GetStarted_cshtml.Execute() in d:\MyProject\Views\ControllerName\ViewName.cshtml:line 43
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.StartPage.RunPage()
   at System.Web.WebPages.StartPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)

在视图中我们有代码

    using (Html.BeginForm("ActionName", "ControllerName"))
    { 
        @Html.AntiForgeryToken()
        ... other codes ...
    }

接收动作方法看起来像

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult ActionName()
    {
        // other logic here

        return RedirectToAction("Something", "Something");
    }

我认为编码应该是正确的。有没有人经历过类似的事情?

4

2 回答 2

0

在我编写了一些使 cookie 无效而不是删除它们的 cookie 清除代码后,我得到了这个异常。当RequestVerificationToken cookie 为空白时,AntiForgeryToken() 似乎失败(即使是在 GET 请求中) 。

于 2012-08-29T18:04:08.313 回答
0

尝试从浏览器中删除所有 cookie。也可以在隐身模式下尝试浏览器或其他浏览器。我有同样的问题。不碰饼干,这发生了。看来问题是由系统还原和 Windows 密码更改引起的。疯狂的..

于 2015-05-29T14:00:27.653 回答