This project is read-only.

Intermittent AntiForgeryException

Topics: Troubleshooting
Aug 17, 2012 at 4:39 PM

Hello Experts,

I am intermittently getting a System.Web.Mvc.HttpAntiForgeryException while adding content to the website. I checked the source code and there is an anti-forgery token in the html. I just cannot figure out why it is not being accepted - here is the stack trace:

[HttpAntiForgeryException (0x80004005): A required anti-forgery token was not supplied or was invalid.]
System.Web.Helpers.AntiForgeryWorker.Validate(HttpContextBase context, String salt) +571
System.Web.Helpers.AntiForgery.Validate(HttpContextBase httpContext, String salt) +39
System.Web.Mvc.ValidateAntiForgeryTokenAttribute.OnAuthorization(AuthorizationContext filterContext) +68
Orchard.Mvc.AntiForgery.AntiForgeryAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext) +310
System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor) +102
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) +50
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8969201
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

So the content adding has to be restarted (that is the annoying part) and it will work the next time.

For some additional insight (may or may not be important)

  • The site is on a multi-tenant arrangement
  • It is hosted on the Windows Azure Website preview
  • I have added a machineKey in the Web.config (as this used to be required, not sure anymore)
  • I have DynamicCompilation disabled in the "HostComponents.config" so it works on the Azure Website framework

I am just wondering if anything in the above stack trace or my settings jumps out at you or how I might go about debugging.  Frequency is about once a week (so you may deem this not worth addressing, I will understand).


Aug 20, 2012 at 8:41 AM

Would you mind filing a bug with any details you may have? Thanks!

Aug 21, 2012 at 10:11 PM

Work item created: