asp.net-mvc 所需的防伪 cookie“__RequestVerificationToken”不存在。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26759102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The required anti-forgery cookie "__RequestVerificationToken" is not present.
提问by user3233312
The required anti-forgery cookie "__RequestVerificationToken" is not present.
所需的防伪 cookie“__RequestVerificationToken”不存在。
I have added in cshtml and in Controller also
我也在 cshtml 和 Controller 中添加了
using (Html.BeginForm())
{
@Html.AntiForgeryToken()
//some code
}
[HttpGet]
[ValidateAntiForgeryToken]
public ActionResult Index()
{
using (var db = new SampleEntities())
{
return View(db.Rfps.ToList());
}
}
采纳答案by Pavel
回答by Justin Skiles
In my case, I had this in my web.config:
就我而言,我的 web.config 中有这个:
<httpCookies requireSSL="true" />
<httpCookies requireSSL="true" />
But my project was set to not use SSL. Commenting out that line or setting up the project to always use SSL solved it.
但是我的项目被设置为不使用 SSL。注释掉该行或将项目设置为始终使用 SSL 解决了这个问题。
回答by Daniel
In my case, it was because I ran another Asp.Net website before. So the cookies could not match for localhost. I cleared my cookies (just for localhost) and everything is fine now.
就我而言,这是因为我之前运行过另一个 Asp.Net 网站。因此 cookie 无法与 localhost 匹配。我清除了我的 cookie(仅用于本地主机),现在一切正常。

