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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 23:18:45  来源:igfitidea点击:

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

asp.net-mvc

提问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

The issue is because you are using a ValidateAntiForgeryTokenattribute on a GET request. You don't need to use this attribute for GETactions. Look herefor more information:

问题是因为您ValidateAntiForgeryToken在 GET 请求上使用了一个属性。您不需要将此属性用于GET操作。看看这里的详细资料:

回答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(仅用于本地主机),现在一切正常。