Home
%3CLINGO-SUB%20id%3D%22lingo-sub-984870%22%20slang%3D%22en-US%22%3EAnti-forgery%20token%20and%20anti-forgery%20cookie%20related%20issues%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-984870%22%20slang%3D%22en-US%22%3E%3CP%3EAnti-forgery%20token%20is%20used%20to%20prevent%20CSRF%20(Cross-Site%20Request%20Forgery)%20attacks.%20Here%20is%20how%20it%20works%20in%20high-level%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EIIS%20server%20associates%20this%20token%20with%20current%20user%E2%80%99s%20identity%20before%20sending%20it%20to%20the%20client%3C%2FLI%3E%0A%3CLI%3EIn%20the%20next%20client%20request%2C%20the%20server%20expects%20to%20see%20this%20token%3C%2FLI%3E%0A%3CLI%3EIf%20the%20token%20is%20missing%20or%20it%20is%20different%2C%20then%20the%20server%20rejects%20the%20request%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Faspnet%2Fcore%2Fsecurity%2Fanti-request-forgery%3Fview%3Daspnetcore-2.2%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EReference%3C%2FA%3E)%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThese%20are%20some%20of%20the%20anti-forgery%20token%20related%20error%20messages%20you%20may%20see%20in%20Event%20Viewer%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CEM%3EThe%20provided%20anti-forgery%20token%20was%20meant%20for%20a%20different%20claims-based%20user%20than%20the%20current%20user.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CEM%3EThe%20provided%20anti-forgery%20token%20was%20meant%20for%20user%20%E2%80%9C%E2%80%9D%2C%20but%20the%20current%20user%20is%20%E2%80%9CX%E2%80%9D.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CEM%3EThe%20anti-forgery%20cookie%20token%20and%20form%20field%20token%20do%20not%20match.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CEM%3EThe%20required%20anti-forgery%20cookie%20%E2%80%9C__RequestVerificationToken%E2%80%9D%20is%20not%20present.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20sample%20stack%20trace%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Eat%20System.Web.Helpers.AntiXsrf.TokenValidator.ValidateTokens(HttpContextBase%20httpContext%2C%20IIdentity%20identity%2C%20AntiForgeryToken%20sessionToken%2C%20AntiForgeryToken%20fieldToken)at%20System.Web.Helpers.AntiXsrf.AntiForgeryWorker.Validate(HttpContextBase%20httpContext)at%20System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext%20controllerContext%2C%20IList%601%20filters%2C%20ActionDescriptor%20actionDescriptor)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F154963i23464F8554779F6A%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_0.jpeg%22%20title%3D%22clipboard_image_0.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EError%20messages%20clearly%20state%20the%20root%20causes%20but%20the%20solution%20is%20not%20always%20straightforward.%20I%20will%20try%20to%20provide%20possible%20solutions%20in%20the%20post.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1655986940%22%20id%3D%22toc-hId-1655986940%22%3ERoot%20Cause%3C%2FH3%3E%0A%3CP%3E%3CSTRONG%3ELong%20story%20short%3A%26nbsp%3B%3C%2FSTRONG%3EFor%20anti-forgery%20validation%20to%20pass%2C%20the%20security%20token%20of%20the%20session%20token%20must%20be%20equal%20to%20the%20security%20token%20of%20the%20field%20token.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20saw%20different%20names%20for%20these%20cookies%20in%20different%20sources.%20They%20can%20be%20used%20interchangeably%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3ESession%20token%20%3D%20Cookie%20token%3CBR%20%2F%3EField%20token%20%3D%20Form%20token%3CBR%20%2F%3ESecurity%20token%20%3D%20anti-XSRF%20Token%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ELonger%20story%3A%3C%2FSTRONG%3E%26nbsp%3BFor%20validation%20to%20pass%2C%20form%20token%20and%20session%20token%20are%26nbsp%3B%3CEM%3Ecorrelated%26nbsp%3B%3C%2FEM%3E(Important%3A%20This%20is%20not%20comparison%20for%20equivalence.%20You%20can%E2%80%99t%20correlate%20them%20by%20simply%20comparing%20them%20in%20Fiddler).%20There%20is%20anti-XSRF%20token%20inside%20each%20of%20those.%20The%20anti-XSRF%20token%20is%20the%20one%20that%20should%20match%20precisely.%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Faspnet%2Fmvc%2Foverview%2Fsecurity%2Fxsrfcsrf-prevention-in-aspnet-mvc-and-web-pages%23validating-the-tokens%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EReference%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20the%20example%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20style%3D%22font-weight%3A%20400%3B%22%3ECookie%2FSession%20token%3A%3CBR%20%2F%3E%3CSTRONG%3EAq81hoVCPIpq3Q6xjBi0EFKKwSFwnKROgS7tyXF393eAN8rdMNZwkVkEgjQokKviKLVST1iWdgDxBt-g3FIughAsczUO7tyWhtz3fs88xMM1%3C%2FSTRONG%3E%3CBR%20%2F%3EAfter%20decoding%3A%26nbsp%3B%3CSTRONG%3E01-1A-CF-C9-ED-F1-3E-1E-7D-C9-9E-BE-90-2E-22-91-36%3C%2FSTRONG%3E-01%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%20style%3D%22font-weight%3A%20400%3B%22%3EForm%20token%3A%3CBR%20%2F%3E%3CSTRONG%3Ei411mJIr0mZKrk17g4Hf-0_G6aXOJLkzzGfd5yn2mVsTqj-35j_n0YUUCzFRXoFet3BXUVpBicpL3p-AqPPA3XEXEtykt4X-_MbRIxLQH6M1%3C%2FSTRONG%3E%3CBR%20%2F%3EAfter%20decoding%3A%26nbsp%3B%3CSTRONG%3E01-1A-CF-C9-ED-F1-3E-1E-7D-C9-9E-BE-90-2E-22-91-36%3C%2FSTRONG%3E-00-00-00-00%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EAs%20you%20see%20above%2C%20the%20raw%20tokens%20are%20different%20but%20extracted%20anti-XSRF%20tokens%20are%20the%20same%20so%20the%20validation%20passes.%20(There%20are%20additional%20bytes%20at%20the%20end.%20They%20are%20flags.%20The%20username%20was%20going%20to%20be%20encoded%20there%20if%20it%20was%20an%20authenticated%20user).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--896170021%22%20id%3D%22toc-hId--896170021%22%3ESolution%3C%2FH3%3E%0A%3CP%3EA%20possible%20solution%20to%20anti-forgery%20related%20errors%20depends%20on%20the%20way%20how%20the%20issue%20occurs.%20I%20would%20recommend%20trying%20to%20find%20out%20the%20user%20behavior%20that%20causes%20these%20errors.%3C%2FP%3E%0A%3CH5%20id%3D%22toc-hId-453613304%22%20id%3D%22toc-hId-453613304%22%3E%26nbsp%3B%3C%2FH5%3E%0A%3CH5%20id%3D%22toc-hId--2098543657%22%20id%3D%22toc-hId--2098543657%22%3EUser%20behavior%3C%2FH5%3E%0A%3CP%3EIn%20my%20case%2C%20the%20clients%20were%20using%20the%20application%20in%20a%20way%20that%20is%20not%20supposed%20to%20be%20used.%20For%20example%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EUser%20goes%20to%20the%20login%20page%3C%2FLI%3E%0A%3CLI%3EUser%20opens%20a%20second%20tab%20in%20the%20same%20browser%20and%20goes%20to%20the%20login%20page%3C%2FLI%3E%0A%3CLI%3EUser%20logins%20in%20the%20first%20tab%20(or%20the%26nbsp%3B%20second%2C%20the%20order%20doesn%E2%80%99t%20matter)%3C%2FLI%3E%0A%3CLI%3EUser%20attempts%20to%20login%20in%20the%20remaining%20login%20tab%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EInforming%20your%20users%20about%20the%20points%20below%20can%20significantly%20reduce%20the%20number%20of%20anti-forgery%20errors%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EUsing%20the%20application%20only%20in%20one%20tab%3C%2FLI%3E%0A%3CLI%3ENot%20using%20the%20Back%20button%20to%20go%20back%20to%20the%20login%20page%3C%2FLI%3E%0A%3CLI%3EUsing%20%E2%80%9CLog%20out%E2%80%9D%20button%20once%20they%20are%20done%20with%20the%20application%3C%2FLI%3E%0A%3CLI%3EThere%20might%20be%20other%20related%20scenarios.%20I%20would%20recommend%20contacting%20your%20users%20and%20asking%20what%20action%20they%20took%20to%20generate%20the%20issue%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH4%20id%3D%22toc-hId--159219817%22%20id%3D%22toc-hId--159219817%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH5%20id%3D%22toc-hId-1387077013%22%20id%3D%22toc-hId-1387077013%22%3ECatch%20the%20Exception%3C%2FH5%3E%0A%3CP%3ECatching%20the%20anti-forgery%20exceptions%20in%20your%20code%20and%20redirecting%20user%20to%20the%20homepage%20if%20they%20are%20already%20authenticated%20should%20prevent%20most%20of%20the%20errors.%20Here%20is%20a%20sample%20code%20block%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%5BHttpPost%5D%0A%5BAllowAnonymous%5D%0A%5BValidateAntiForgeryToken%5D%0Apublic%20ActionResult%20Login(LoginModel%20model%2C%20string%20returnUrl)%0A%7B%0A...%0A%7D%0A%20%0Aprotected%20override%20void%20OnException(ExceptionContext%20filterContext)%0A%7B%0A%20%20%20%20base.OnException(filterContext)%3B%0A%20%0A%20%20%20%20var%20action%20%3D%20filterContext.RequestContext.RouteData.Values%5B%22action%22%5D%20as%20string%3B%0A%20%20%20%20var%20controller%20%3D%20filterContext.RequestContext.RouteData.Values%5B%22controller%22%5D%20as%20string%3B%0A%20%0A%20%20%20%20if%20((filterContext.Exception%20is%20HttpAntiForgeryException)%20%26amp%3B%26amp%3B%0A%20%20%20%20%20%20%20%20action%20%3D%3D%20%22Login%22%20%26amp%3B%26amp%3B%0A%20%20%20%20%20%20%20%20controller%20%3D%3D%20%22MyController%22%20%26amp%3B%26amp%3B%0A%20%20%20%20%20%20%20%20filterContext.RequestContext.HttpContext.User%20!%3D%20null%20%26amp%3B%26amp%3B%0A%20%20%20%20%20%20%20%20filterContext.RequestContext.HttpContext.User.Identity.IsAuthenticated)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20filterContext.ExceptionHandled%20%3D%20true%3B%0A%20%0A%20%20%20%20%20%20%20%20%2F%2F%20redirect%2Fshow%20error%2Fwhatever%3F%0A%20%20%20%20%20%20%20%20filterContext.Result%20%3D%20new%20RedirectResult(%22%2Fhomepage%22)%3B%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20may%20take%20time%20to%20fine%20tune%20this%20code%20block.%20There%20is%20no%20one%20solution%20that%20fits%20all.%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--968566443%22%20id%3D%22toc-hId--968566443%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH5%20id%3D%22toc-hId-577730387%22%20id%3D%22toc-hId-577730387%22%3ERemove%20the%20anti-forgery%20validation%20from%20the%20login%20page%3C%2FH5%3E%0A%3CP%3EI%20saw%20customers%20not%20using%20the%20anti-forgery%20validation%20in%20the%26nbsp%3B%3CSTRONG%3Epublic%20pages%3C%2FSTRONG%3E%26nbsp%3Bsuch%20as%20login%2C%20about%2C%20register%20pages.%20Anti-forgery%20token%E2%80%99s%20main%20purpose%20is%20to%20prevent%20attacker%20using%20authentication%20cookie%20for%20doing%20things%20on%20behalf%20of%20the%20actual%20user.%20Since%20the%20user%20isn%E2%80%99t%20authenticated%20yet%20in%20the%20login%20page%2C%20there%20are%20customers%20removing%20the%20validation.%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--1777913069%22%20id%3D%22toc-hId--1777913069%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH5%20id%3D%22toc-hId--231616239%22%20id%3D%22toc-hId--231616239%22%3ETry%20quick%20fixes%3C%2FH5%3E%0A%3CP%3EThe%20common%20%E2%80%9Cpossible%20solutions%E2%80%9D%20to%20anti-forgery%20token%2Fcookie%20related%20issues%20are%20disabling%20output%20caching%20and%20enabling%20heuristic%20checks.%20I%20will%20include%20the%20code%20snippets%20here.%3C%2FP%3E%0A%3CP%3EDisable%20output%20caching%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%5BOutputCache(NoStore%20%3D%20true%2C%20Location%20%3D%20System.Web.UI.OutputCacheLocation.None)%5D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdd%20%E2%80%9Cheuristic%20checks%E2%80%9D%20to%20the%20Application_Start%20method%20of%20Global.asax%20file%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EAntiForgeryConfig.SuppressIdentityHeuristicChecks%20%3D%20true%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-984870%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20style%3D%22display%3A%20inline%20!important%3B%20float%3A%20none%3B%20background-color%3A%20%23ffffff%3B%20color%3A%20%23333333%3B%20cursor%3A%20text%3B%20font-family%3A%20inherit%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.7142%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%3EAnti-forgery%20token%20is%20used%20to%20prevent%20CSRF%20(Cross-Site%20Request%20Forgery)%20attacks.%20Here%20is%20how%20it%20works%20in%20high-level%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Microsoft

Anti-forgery token is used to prevent CSRF (Cross-Site Request Forgery) attacks. Here is how it works in high-level:

  1. IIS server associates this token with current user’s identity before sending it to the client
  2. In the next client request, the server expects to see this token
  3. If the token is missing or it is different, then the server rejects the request (Reference)

 

These are some of the anti-forgery token related error messages you may see in Event Viewer:

 

The provided anti-forgery token was meant for a different claims-based user than the current user.

The provided anti-forgery token was meant for user “”, but the current user is “X”.

The anti-forgery cookie token and form field token do not match.

The required anti-forgery cookie “__RequestVerificationToken” is not present.

 

A sample stack trace:

 

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.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor)

 

 

clipboard_image_0.jpeg

 

Error messages clearly state the root causes but the solution is not always straightforward. I will try to provide possible solutions in the post.

 

Root Cause

Long story short: For anti-forgery validation to pass, the security token of the session token must be equal to the security token of the field token.

 

I saw different names for these cookies in different sources. They can be used interchangeably:

 

Session token = Cookie token
Field token = Form token
Security token = anti-XSRF Token

 

Longer story: For validation to pass, form token and session token are correlated (Important: This is not comparison for equivalence. You can’t correlate them by simply comparing them in Fiddler). There is anti-XSRF token inside each of those. The anti-XSRF token is the one that should match precisely. Reference

 

For the example:

  • Cookie/Session token:
    Aq81hoVCPIpq3Q6xjBi0EFKKwSFwnKROgS7tyXF393eAN8rdMNZwkVkEgjQokKviKLVST1iWdgDxBt-g3FIughAsczUO7tyWhtz3fs88xMM1
    After decoding: 01-1A-CF-C9-ED-F1-3E-1E-7D-C9-9E-BE-90-2E-22-91-36-01
  • Form token:
    i411mJIr0mZKrk17g4Hf-0_G6aXOJLkzzGfd5yn2mVsTqj-35j_n0YUUCzFRXoFet3BXUVpBicpL3p-AqPPA3XEXEtykt4X-_MbRIxLQH6M1
    After decoding: 01-1A-CF-C9-ED-F1-3E-1E-7D-C9-9E-BE-90-2E-22-91-36-00-00-00-00

As you see above, the raw tokens are different but extracted anti-XSRF tokens are the same so the validation passes. (There are additional bytes at the end. They are flags. The username was going to be encoded there if it was an authenticated user).

 

Solution

A possible solution to anti-forgery related errors depends on the way how the issue occurs. I would recommend trying to find out the user behavior that causes these errors.

 
User behavior

In my case, the clients were using the application in a way that is not supposed to be used. For example:

  1. User goes to the login page
  2. User opens a second tab in the same browser and goes to the login page
  3. User logins in the first tab (or the  second, the order doesn’t matter)
  4. User attempts to login in the remaining login tab

Informing your users about the points below can significantly reduce the number of anti-forgery errors:

  • Using the application only in one tab
  • Not using the Back button to go back to the login page
  • Using “Log out” button once they are done with the application
  • There might be other related scenarios. I would recommend contacting your users and asking what action they took to generate the issue

 

Catch the Exception

Catching the anti-forgery exceptions in your code and redirecting user to the homepage if they are already authenticated should prevent most of the errors. Here is a sample code block:

 

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
...
}
 
protected override void OnException(ExceptionContext filterContext)
{
    base.OnException(filterContext);
 
    var action = filterContext.RequestContext.RouteData.Values["action"] as string;
    var controller = filterContext.RequestContext.RouteData.Values["controller"] as string;
 
    if ((filterContext.Exception is HttpAntiForgeryException) &&
        action == "Login" &&
        controller == "MyController" &&
        filterContext.RequestContext.HttpContext.User != null &&
        filterContext.RequestContext.HttpContext.User.Identity.IsAuthenticated)
    {
        filterContext.ExceptionHandled = true;
 
        // redirect/show error/whatever?
        filterContext.Result = new RedirectResult("/homepage");
    }
}

 

 

 

It may take time to fine tune this code block. There is no one solution that fits all.

 

Remove the anti-forgery validation from the login page

I saw customers not using the anti-forgery validation in the public pages such as login, about, register pages. Anti-forgery token’s main purpose is to prevent attacker using authentication cookie for doing things on behalf of the actual user. Since the user isn’t authenticated yet in the login page, there are customers removing the validation.

 

Try quick fixes

The common “possible solutions” to anti-forgery token/cookie related issues are disabling output caching and enabling heuristic checks. I will include the code snippets here.

Disable output caching:

 

[OutputCache(NoStore = true, Location = System.Web.UI.OutputCacheLocation.None)]

 

Add “heuristic checks” to the Application_Start method of Global.asax file:

 

AntiForgeryConfig.SuppressIdentityHeuristicChecks = true;