1

我使用 asp.net + MVC1.0 并且在网页中我有几个表单,在每个表单中我调用了以下函数 AntiForgeryToken() 来生成隐藏值,并且在控制器函数中我有一个 validate 属性。

当我使用 JMeter 并使用正则表达式捕获令牌然后将令牌与我的表单一起发布到服务器时,我发现它抛出了这样的异常:


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Invalid length for a Base-64 char array.

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

版本信息:  Microsoft .NET Framework 版本:2.0.50727.3603;ASP.NET 版本:2.0.50727.3082

[FormatException]:Base-64 字符数组的长度无效。
   在 System.Convert.FromBase64String(String s)
   在 System.Web.UI.ObjectStateFormatter.Deserialize(字符串输入字符串)
   在 System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(字符串序列化状态)
   在 System.Web.Mvc.AntiForgeryDataSerializer.Deserialize(字符串序列化令牌)
[HttpAntiForgeryException]:所​​需的防伪令牌未提供或无效。
   在 System.Web.Mvc.AntiForgeryDataSerializer.Deserialize(字符串序列化令牌)
   在 System.Web.Mvc.ValidateAntiForgeryTokenAttribute.OnAuthorization(AuthorizationContext filterContext)
   在 System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext 控制器上下文,IList`1 过滤器,ActionDescriptor actionDescriptor)
   在 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext 控制器上下文,字符串 actionName)
   在 System.Web.Mvc.Controller.ExecuteCore()
   在 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   在 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   在 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext)
   在 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext)
   在 System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext)
   在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   在 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤,Boolean& completedSynchronously)

此错误页面可能包含敏感信息,因为 ASP.NET 配置为使用 <customErrors mode="Off"/> 显示详细错误消息。考虑在生产环境中使用 <customErrors mode="On"/> 或 <customErrors mode="RemoteOnly"/>。

而且我确定捕获的令牌与我们生成的完全一样,为什么会发生这个异常?

4

1 回答 1

1

刚刚解决,因为我在发布到服务器之前没有对令牌进行编码。

于 2010-08-04T07:50:18.777 回答