Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Occasional __RequestVerificationToken errors

I've got an MVC web app on azure, and a couple of hundred times a day, I get an The required anti-forgery cookie "__RequestVerificationToken" is not present. in my unhandled exceptions logs.

I've set everything up correctly, my action method has the [ValidateAntiForgeryToken].

I can see from looking at the exception details that the token was present in the form, but the cookie was not present.

Anyone know what might cause this?

Here's the error in full.

System.Web.Mvc.HttpAntiForgeryException (0x80004005): The required anti-forgery cookie "__RequestVerificationToken" is not present.
   at System.Web.Helpers.AntiXsrf.TokenValidator.ValidateTokens(HttpContextBase httpContext, IIdentity identity, AntiForgeryToken sessionToken, AntiForgeryToken fieldToken)
   at System.Web.Helpers.AntiXsrf.AntiForgeryWorker.Validate(HttpContextBase httpContext)
   at System.Web.Helpers.AntiForgery.Validate()
like image 258
Matt Roberts Avatar asked Dec 09 '14 12:12

Matt Roberts


People also ask

What is __ Requestverificationtoken?

TYPE. __RequestVerificationToken. www.grpgroup.co.uk. This is an anti-forgery cookie set by web applications built using ASP.NET MVC technologies. It is designed to stop unauthorised posting of content to a website, known as Cross-Site Request Forgery.

What is Antiforgery token could not be decrypted?

Error: The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster, ensure that all machines are running the same version of ASP.NET Web Pages and that the <machineKey> configuration specifies explicit encryption and validation keys. AutoGenerate cannot be used in a cluster.

What is HTML AntiForgeryToken () in MVC?

AntiForgeryToken() Generates a hidden form field (anti-forgery token) that is validated when the form is submitted. AntiForgeryToken(String) Obsolete. Generates a hidden form field (anti-forgery token) that is validated when the form is submitted.


1 Answers

This can be caused by many issues. Things that can cause the issue:

  • Bots or clients without enabled cookies
  • Too many cookies being created on client (there is only so many cookies browser can handle per domain) and AntiForgeryCookie ends up being removed
like image 140
Ondrej Svejdar Avatar answered Sep 25 '22 13:09

Ondrej Svejdar