I am using Membership.create
user function, then the following error is occurring,
The required anti-forgery form field \"__RequestVerifi
Sometimes you are writing a form action method with a result list. In this case, you cannot work with one action method. So you have to have two action methods with the same name. One with [HttpGet]
and another with [HttpPost]
attribute.
In your [HttpPost]
action method, set [ValidateAntiForgeryToken]
attribute and also put @Html.AntiForgeryToken()
in your html form.
In my EPiServer solution on several controllers there was a ContentOutputCache attribute on the Index action which accepted HttpGet. Each view for those actions contained a form which was posting to a HttpPost action to the same controller or to a different one. As soon as I removed that attribute from all of those Index actions problem was gone.
In my case, I had this javascript on the form submit:
$('form').submit(function () {
$('input').prop('disabled', true);
});
This was removing the hidden RequestVerificationToken from the form being submitted. I changed that to:
$('form').submit(function () {
$('input[type=submit]').prop('disabled', true);
$('input[type=text]').prop('readonly', true);
$('input[type=password]').prop('readonly', true);
});
... and it worked fine.
Another possibility for those of us uploading files as part of the request. If the content length exceeds <httpRuntime maxRequestLength="size in kilo bytes" />
and you're using request verification tokens, the browser displays the 'The required anti-forgery form field "__RequestVerificationToken" is not present'
message instead of the request length exceeded message.
Setting maxRequestLength to a value large enough to cater for the request cures the immediate issue - though I'll admit it's not a proper solution (we want the user to know the true problem of file size, not that of request verification tokens missing).
If anyone experiences the error for the same reason why I experience it, here's my solution:
if you had Html.AntiForgeryToken();
change it to @Html.AntiForgeryToken()
All the other answers in here are also valid, but if none of them solve the issue it is also worth checking that the actual headers are being passed to the server.
For example, in a load balanced environment behind nginx, the default configuration is to strip out the __RequestVerificationToken header before passing the request on to the server, see: simple nginx reverse proxy seems to strip some headers