1

私はasp.net+MVC1.0を使用しており、Webページにはいくつかのフォームがあり、各フォーム内で次の関数AntiForgeryToken()を呼び出して非表示の値を生成し、Controller関数には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(String inputString)で
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)で
   System.Web.Mvc.AntiForgeryDataSerializer.Deserialize(String serializedToken)で
[HttpAntiForgeryException]:必要な偽造防止トークンが提供されていないか、無効でした。
   System.Web.Mvc.AntiForgeryDataSerializer.Deserialize(String serializedToken)で
   System.Web.Mvc.ValidateAntiForgeryTokenAttribute.OnAuthorization(AuthorizationContext filterContext)で
   System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext、IList`1フィルター、ActionDescriptor actionDescriptor)で
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext、String 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 step、Boolean&completedSynchronously)で

ASP.NETは<customErrorsmode= "Off" />を使用して詳細なエラーメッセージを表示するように構成されているため、このエラーページには機密情報が含まれている可能性があります。実稼働環境では、<customErrors mode ="On"/>または<customErrorsmode="RemoteOnly"/>の使用を検討してください。

そして、キャプチャされたトークンは私たちが生成したものとまったく同じであると確信していますが、なぜこの例外が発生したのですか?

4

1 に答える 1

1

サーバーに投稿する前にトークンをエンコードしなかったため、解決しました。

于 2010-08-04T07:50:18.777 に答える