AngularJS can't find XSRF-TOKEN cookie

后端 未结 1 831
-上瘾入骨i
-上瘾入骨i 2021-01-07 03:05

I\'m using angular 1.0.4 with an ASP.NET MVC4 + Web API project. I\'m trying to leverage angular\'s CSRF protection to no avail. I can see that I\'m passing along a cookie n

相关标签:
1条回答
  • 2021-01-07 03:42

    I could not find an exact answer to my question. I ended up creating a service to find the 'input[name="__RequestVerificationToken"]', get its value, and return an object with that value. I then set the headers in the config using that object. This lets me lazily extract and append the value as a header for a form that doesn't appear immediately on the page.

    I also realized, upon further review, that ASP.NET's AntiForgeryToken support requires both the cookie and form input/header value to validate, so the built-in AngularJS support wouldn't suffice anyway.

    If anyone has a better solution, I will happily transfer the answer to that solution.

    0 讨论(0)
提交回复
热议问题