c# - Why can't I get the vaue of __RequestVerificationToken from AngularJS or even pure JavaScript? -


I am writing a front-end application with Bootstrap and AngularRes for a C # MVC back-end code.

Using Chrome's Developer Console (and any other browsers including IE), I can see a cookie called __ request VerificationToken , as shown below. :

Enter image details here

I understand that This is a technique that is used to stop the attacks. Anyway, since this cookie, I was trying to get the value of using anglers js module $ cookies , but it always returns undefined , and print < Code> document.cookie does not show the code below:

  ... this.initApp = function () {console.log ('__Request Verification value: '' $ Cookies .__ Request VerificationToken + '' '); // angular path console.log ('cookie:' 'document.cookie +' '' '); // pure javascript}; ...  

So my question is, if cookie is present and every one is being sent to the customer in response, then why can not I value it, and how do I get it?

You have the [ValidateAntiForgeryToken] attribute that writes a unique value Before action, you should add @ Html.AnttiForgeryToken () to your code and the same value is written as hidden field. Is there.

  var token = $ ('input [name = "__ requestVerificationToken"]'); Val () .;  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -