我正在使用
Membership.create
用户函数,但出现以下错误,
我该如何解决?所需的防伪造表单字段“__RequestVerificationToken”不存在
Membership.create
用户函数,但出现以下错误,
我该如何解决?所需的防伪造表单字段“__RequestVerificationToken”不存在
[ValidateAntiForgeryToken]
属性。您还应该在表单中添加@Html.AntiForgeryToken()
。IIS
中有这个绑定(https»EmptyHostName»IP»443
),但没有一个绑定(https»www.mysite.com»IP»443
)。因此,我添加了一个新的绑定,其中https
的非空主机名等于该域,并解决了问题。我在IIS
中设置了重写设置,以强制使用http 2 https
。 - Ramin Bateni就像这样:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult MethodName(FormCollection formCollection)
{
...
Code Block
...
}
@using(Html.BeginForm())
{
@Html.AntiForgeryToken()
<input name="..." type="text" />
// rest
}
[HttpGet]
public ActionResult MethodName()
{
..
}
即使未启用Cookies,您仍将收到该错误。
在我的情况下,是由于在webconfig中添加requireSSL=true
到httpcookies
导致AntiForgeryToken停止工作。例如:
<system.web>
<httpCookies httpOnlyCookies="true" requireSSL="true"/>
</system.web>
requireSSL=true
和@Html.AntiForgeryToken()
都能起作用,我在Global.asax
的Application_BeginRequest
中添加了这行代码。 protected void Application_BeginRequest(object sender, EventArgs e)
{
AntiForgeryConfig.RequireSsl = HttpContext.Current.Request.IsSecureConnection;
}
<httpRuntime maxRequestLength="以千字节为单位的大小" />
,并且您正在使用请求验证令牌,则浏览器会显示'所需的防伪表单字段“__RequestVerificationToken”不存在'
消息,而不是请求长度超过消息。$('form').submit(function () {
$('input').prop('disabled', true);
});
$('form').submit(function () {
$('input[type=submit]').prop('disabled', true);
$('input[type=text]').prop('readonly', true);
$('input[type=password]').prop('readonly', true);
});
...然后它运行得很好。
readonly
并排除了隐藏的控件。看起来效果很好。 - Sean在您的控制器中,请确保您拥有您的http属性,例如:
[HttpPost]
[ValidateAntiForgeryToken]
@Html.AntiForgeryToken();
我在代码块中使用了Html.AntiForgeryToken(),但没有加上@符号,在Razor中并没有出现错误,但在运行时却出错了。 确保你注意到@Html.Ant..中的@符号是否存在
Html.AntiForgeryToken();
不起作用!!改成@Html.AntiForgeryToken()
就可以了。 - FindOutIslamNow