我在 .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");
}
我认为编码应该是正确的。有没有人经历过类似的事情?