2

I am getting a famous asp mvc error:

The required anti-forgery cookie "__RequestVerificationToken" is not present.

I am only getting this error when deploying my site to godaddy server and only on the login page. However, all it takes is for me to refresh the page and the error is gone.

Thus, i trying to figure out how to check if this cookie exists and run:

location.reload(true); 

if cookie does not exist, which i think will solve the problem.

So i tried to use:

if(!$.cookie('__RequestVerificationToken')){
    location.reload(true);
}

But the cookie is always undefined and the above code keeps reloading the page.

I have checked almost every SO question relating to this problem and cannot seem to find the answer.

JustLearning
  • 3,164
  • 3
  • 35
  • 52
  • the cookie name is usually something like `__RequestVerificationToken_L0F3ZXNvbWV...` so you have the wrong name – Omu Feb 23 '19 at 09:06

2 Answers2

0

Well, $.cookie is not built-in to jQuery. It requires a plugin. If you don't have that plugin, that's going to come back as undefined and testing !undefined is always going to be true. As a result, I would assume you found that code somewhere, assumed it was part of jQuery, and didn't bother to include the plugin that actually makes it work as a result. Additionally, that syntax and the associated plugin has been deprecated in favor of the JavaScript Cookie project, so use that rather than the old jQuery Cookie plugin.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
0

Check your Web.config and if present comment the following line

httpOnlyCookies="true" requireSSL="true".