所需的防伪cookie"__RequestVerificationToken"不存在.

use*_*312 11 asp.net-mvc

所需的防伪cookie"__RequestVerificationToken"不存在.

我已经在cshtml和Controller中添加了

 using (Html.BeginForm())
 {
   @Html.AntiForgeryToken()

  //some code

  }

     [HttpGet]
    [ValidateAntiForgeryToken]
    public ActionResult Index()
    {
        using (var db = new SampleEntities())
        {
            return View(db.Rfps.ToList());
        }



    }
Run Code Online (Sandbox Code Playgroud)

Jus*_*les 34

在我的情况下,我在我的web.config中有这个:

<httpCookies requireSSL="true" />

但我的项目设置为不使用SSL.注释掉该行或设置项目以始终使用SSL解决了它.

  • 这个答案对我有所帮助.在开发过程中通常不使用SSL,因此将**httpCookies**设置为需要SSL会导致在访问**localhost**时访问网站时不发送cookie.只需确保在部署时将其设置为true - 我通常在我的Web.Release.config文件中执行此操作. (4认同)
  • 当应用程序移到终止 SSL 的设备而不是执行 SSL 的 Web 服务器后面时,我遇到了这个问题。 (2认同)

小智 7

问题是因为您设置ValidateAntiForgeryToken了仅允许GET请求的操作属性.您不需要使用with属性进行GET操作.看这里了解更多信息