As I have deployed my newly created Asp.Net MVC web application to the server, I am facing the subject error, upon submitting a sign-up form. It is working fine in my local environment.
In my controller's action method, I have set the attribute to validate the token as shown below:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
////
}
And in my view, I have set as:
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
}
////
)
One more thing is that I have enabled SSL on my project properties. I have also added <httpCookies httpOnlyCookies="true" requireSSL="true"/>
in my web.config file.
While inspecting, I can see the hidden element <input name="__RequestVerificationToken" type="hidden" value="blaa blaa>"
, but i cannot see any cookie present there.
After hours of troubleshooting, I am still unable to find a solution to this problem. I am always getting error The required anti-forgery cookie "__RequestVerificationToken" is not present.
How to get rid of this?
I myself has find the answer to this question. In my case, as I have set SSL to true, I need to have a security certificate. So, I purchased and configured the certificate on my hosted site and the error has gone.