【问题标题】:FireFox 4 and <%=Html.AntiForgeryToken()%> troubleFireFox 4 和 <%=Html.AntiForgeryToken()%> 麻烦
【发布时间】:2011-04-08 10:12:02
【问题描述】:

当我尝试使用 FireFox4 登录时,我收到了错误消息(其他浏览器没有错误):

检查表单 MAC 的状态失败。如果应用程序是 Web Farm 或集群,请确保配置指向相同的验证密钥 validationKey 和验证算法。 AutoGenerate 不能在集群中使用。

[ViewStateException: 
    Client IP: ::1
    Port: 
    User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:2.0) Gecko/20100101 Firefox/4.0
    ViewState: X+K7IAAB3XrqQMf0Ym7ZlHeMzvcISEek8a8NX07/uIQ1jEdwJp+/fisjPu64BgVKohucBKZxiX6vdxG+GNAS4qGMJbyCAfB6hwEKvpR9Df9o9gBj5MJTF2AHA6YO87XVvqbC3TNlTBSQ1OLakVvy7Q==
    Referer: http://localhost:1062/
    Path: /login]

登录页面很简单:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" Inherits="ModelViewPage<Graphite.Web.Controllers.Login.LoginViewModel>" %>
<%@ Import Namespace="Graphite.Web.Controllers.Login" %>

<asp:Content ContentPlaceHolderID="main" runat="server" >
<%
  using (Html.BeginForm("Authenticate","Login")) {%>
  <div class="formInput"> 
       <%= this.TextBox(x => x.Username).Label("Username: ")%>
  </div>
  <div class="formInput">
      <%= this.Password(x => x.Password).Label("Password: ")%>
  </div>
  <%=Html.AntiForgeryToken()%>
  <%=this.SubmitButton("Login")%>
<%
  }%>
</asp:Content>

我试图禁用诸如无脚本之类的愤怒添加,但它对我没有帮助。

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-3 firefox4


    【解决方案1】:

    检查页面在登录按钮上发布的 URL 是什么(您可以使用 firebug)。我的怀疑是它正在回发到 aspx 页面 - 而不是发布到将被路由到正确控制器的 url。

    另外,我建议您在 MVC 中禁用 ASP.NET 页面中的视图状态,因为您仅将它们用于呈现输出,而不是真正使用其控制和回发模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多