2

我正在尝试Html.AntiForgeryToken在 Mono (XSP) 下使用 ASP.NET MVC,但它不起作用。它引发以下异常。有任何想法吗?

System.ArgumentNullException: Argument cannot be null.
Parameter name: inputString
  at System.Web.UI.ObjectStateFormatter.Deserialize (System.String inputString) [0x00006] in /home/danipen/Downloads/mono-2.8/mcs/class/System.Web/System.Web.UI/ObjectStateFormatter.cs:131 
  at System.Web.UI.HiddenFieldPageStatePersister.Load () [0x00007] in /home/danipen/Downloads/mono-2.8/mcs/class/System.Web/System.Web.UI/HiddenFieldPageStatePersister.cs:57 
  at System.Web.UI.Page.LoadPageStateFromPersistenceMedium () [0x0000f] in /home/danipen/Downloads/mono-2.8/mcs/class/System.Web/System.Web.UI/Page.cs:1763 
  at System.Web.UI.Page.LoadPageViewState () [0x00000] in /home/danipen/Downloads/mono-2.8/mcs/class/System.Web/System.Web.UI/Page.cs:1769 
  at System.Web.UI.Page.RestorePageState () [0x00051] in /home/danipen/Downloads/mono-2.8/mcs/class/System.Web/System.Web.UI/Page.cs:1454 
  at System.Web.UI.Page.InternalProcessRequest () [0x001b9] in /home/danipen/Downloads/mono-2.8/mcs/class/System.Web/System.Web.UI/Page.cs:1433 
  at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context) [0x0005b] in /home/danipen/Downloads/mono-2.8/mcs/class/System.Web/System.Web.UI/Page.cs:1261 

你知道实现这个的任何其他方法吗?

先谢谢了。

编辑:这是我的视图代码(它是部分视图)。如果我删除该行<%= Html.AntiForgeryToken() %>一切正常,在其他情况下它会抛出上述异常。

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Codice.Web.Client.Comment>" %>

<div class="comment" style="background-color: #009ACF">
 <div class="comment-meta">
  <p class="comment-author">
   <span class="avatarimage">
    <%= Html.AvatarFor(Model.CommentInfo.Owner) %>
   </span>
   <strong class="comment-author">
     <%= Html.Encode(Model.GetAuthorString()) %>
   </strong>
   says:
  </p>
  <p class="comment-date">
   <%= Html.TimeAgo(Model.CommentInfo.LocalTimeStamp) %>
  </p>
 </div>

 <div class="comment-body">
  <div class="formatted-content">
   <%= Html.Encode(Model.CommentInfo.Comment) %>
  </div>
  <div class="form-content">
   <% using(Html.BeginForm(
                   "EditComment",
                   "Comments",
                   new
                   {
        repository = Model.Repository,
        commentId = Model.CommentInfo.Id
       },
                   FormMethod.Post,
                   null))
       { %>
           <%= Html.AntiForgeryToken() %>
        <%= Html.TextBox("newComment", Model.CommentInfo.Comment) %>

        <div class="form-actions">
         <a class"edit-cancel minibutton" href="#">
          <span>Cancel</span>
         </a>
         <button class="minibutton" type="submit">
          <span>Update comment</span>
         </button>
        </div>
        <%
       }
   %>
  </div>
 </div>
</div>
4

1 回答 1

2

您是否[ValidateAntiForgeryToken]在为 POST 动词服务的控制器操作上设置了属性?

编辑:这个问题的可能解决方案可能是使用来自 master 分支的最新单声道,因为这个问题可以在旧版本的单声道上复制(例如 4 月 22 日的 tarball 导致相同的异常)。

编辑 2:让这项工作真正需要的是在 web.config 文件中设置有效的machineKey 元素。例如,可以使用实用程序生成密钥。

于 2010-12-03T12:13:56.573 回答