2

モノラル(XSP)でASP.NET MVCを使用しようとしていますが、Html.AntiForgeryToken機能しません。次の例外がスローされます。何か案は?

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

POST動詞を提供しているコントローラーアクションに属性が設定されてい[ValidateAntiForgeryToken]ますか?

編集:この問題の可能な解決策は、おそらくマスターブランチからの最新のモノラルを使用することです。これは、この問題が古いバージョンのモノラルで再現される可能性があるためです(たとえば、4月22日のtarballが同じ例外を引き起こしています)。

編集2:これを機能させるためにおそらく本当に必要なのは、web.configファイルに有効なmachineKey要素を設定することです。キーは、たとえばこのユーティリティを使用して生成できます。

于 2010-12-03T12:13:56.573 に答える