我有一个表格帖子,一直给我一个反伪造令牌错误.
这是我的表格:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.EditorFor(m => m.Email)
@Html.EditorFor(m => m.Birthday)
<p>
<input type="submit" id="Go" value="Go" />
</p>
}
Run Code Online (Sandbox Code Playgroud)
这是我的行动方法:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Join(JoinViewModel model)
{
//a bunch of stuff here but it doesn't matter because it's not making it here
}
Run Code Online (Sandbox Code Playgroud)
这是web.config中的machineKey:
<system.web>
<machineKey validationKey="mykey" decryptionKey="myotherkey" validation="SHA1" decryption="AES" />
</system.web>
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
A required anti-forgery token was not supplied or was invalid.
Run Code Online (Sandbox Code Playgroud)
我已经读过,更改HttpContext上的用户会使令牌无效,但这不会发生在这里.我的Join操作上的HttpGet只返回视图:
[HttpGet]
public ActionResult Join()
{
return this.View();
}
Run Code Online (Sandbox Code Playgroud)
所以我不确定发生了什么.我一直在搜索,似乎所有东西都表明它是机器键更改(应用程序周期)或用户/会话更改.
还有什么可以继续?我该如何解决这个问题?
我有一个ASP.Net调查问卷应用程序,它将数据重新提交到同一页面,每次都显示一个不同的问题.有BACK和NEXT按钮可以在问题之间导航.
我想检测何时提交表单是因为浏览器刷新而不是按下其中一个按钮.我遇到了一个WebForms方法,但不知道如何在MVC 2应用程序中应用这些主体,因为页面事件不可用(据我所知......我对微软的MVC模型很新).
如何将该原则应用于MVC 2?有没有更好的方法来检测刷新?