启用S​​SL时的防伪令牌错误

时间:2015-02-21 17:07:31

标签: c# asp.net-mvc iis ssl antiforgerytoken

我在VS 2013中创建了默认的MVC 5网站应用程序,我唯一做的就是启用SSL。

每当我在Firefox上提交第二张表格(首次提交罚款)时,我都会收到此错误:

  

无法解密防伪令牌。如果此应用程序由Web场或群集托管,请确保所有计算机都运行相同版本的ASP.NET网页,并且配置指定显式​​加密和验证密钥。无法在群集中使用AutoGenerate。

每当我提交第二张表格时,我都会收到此错误:

  

所需的防伪cookie" __ RequestVerificationToken"不存在。

使用IE无论如何都不会出错。

我已尝试在web.config中生成并粘贴机器密钥,但它没有帮助 我试图重新创建项目/重新启动IIS /尝试IIS 7而不是IIS Express,但仍然没有好处。 禁用SSL有效,但我的项目中需要SSL。

[ValidateForgeryAttribute]在每个POST操作之前设置,该操作是通过设置@ Html.AntiForgeryToken()的提交表单调用的。

更新

这是在提交时导致异常的表单示例,但请记住,每次使用@ Html.AntiForgeryToken()进行提交(以及相应Action上的相同属性修饰)。

using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl })) {
    @Html.AntiForgeryToken()
    <div id="socialLoginList">
        <p>
            @foreach (AuthenticationDescription p in loginProviders) {
                <button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
            }
        </p>
    </div>
}

行动代码:

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
    // Request a redirect to the external login provider
    return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
}

0 个答案:

没有答案