gpt4 book ai didi

asp.net-mvc - 解决防伪 token 问题

转载 作者:行者123 更新时间:2023-12-03 08:16:08 25 4
gpt4 key购买 nike

我有一个表单帖子,始终给我一个防伪 token 错误。

这是我的表格:

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.EditorFor(m => m.Email)
@Html.EditorFor(m => m.Birthday)
<p>
<input type="submit" id="Go" value="Go" />
</p>
}

这是我的操作方法:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Join(JoinViewModel model)
{
//a bunch of stuff here but it doesn't matter because it's not making it here
}

这是web.config中的machineKey:
<system.web>
<machineKey validationKey="mykey" decryptionKey="myotherkey" validation="SHA1" decryption="AES" />
</system.web>

这是我得到的错误:
A required anti-forgery token was not supplied or was invalid.

我已经读过,在HttpContext上更改用户将使 token 无效,但这在这里没有发生。我的Join Action 上的HttpGet仅返回 View :
[HttpGet]
public ActionResult Join()
{
return this.View();
}

所以我不确定发生了什么。我到处搜索,似乎所有内容都表明是更改了MachineKey(应用程序周期)还是更改了用户/ session 。

还有什么可能发生?我该如何解决?

最佳答案

我不知道您的意思是您能够按需获取该错误-还是在日志中看到该错误,但是无论如何,这是保证反伪造 token 错误的一种方法。

等等...

  • 确保您已注销,然后输入您的登录信息
  • 双击登录按钮
  • 您将获得:

  • The provided anti-forgery token was meant for user "", but the current user is "XXX@yahoo.com".



    (现在,我将假定此确切的错误消息在MVC4中已更改,并且实际上与您得到的消息相同)。

    还有很多人仍然双击所有内容-这很糟糕! 我刚醒来就想通了,所以我真的不知道如何通过测试。您甚至不必双击-如果按钮无响应,当我第二次单击时,我自己会遇到此错误。

    我只是删除了验证属性。我的网站始终是SSL,并且我不太担心风险。我只需要它现在就可以工作。另一个解决方案是使用javascript禁用按钮。

    这可以在MVC4初始安装模板上复制。

    关于asp.net-mvc - 解决防伪 token 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5767768/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com