ASP.NET MVC: fonctionne AntiForgeryToken en mono?
-
30-09-2019 - |
Question
Je suis en train d'utiliser le Html.AntiForgeryToken
dans ASP.NET MVC sous Mono (XSP) et il ne fonctionne pas. Il jette l'exception suivante. Toutes les idées?
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
Avez-vous une autre façon de mettre en œuvre ce?
Merci d'avance.
Modifier : Ceci est mon code de la vue (il est une vue partielle). Si je supprime la ligne <%= Html.AntiForgeryToken() %>
toutes fins de travaux, dans d'autres cas, il thows l'exception décrite ci-dessus.
<%@ 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>
La solution
Avez-vous [ValidateAntiForgeryToken]
jeu d'attributs sur l'action que vous contrôleur qui sert le verbe POST?
Edit: Solution possible de ce problème est probablement d'utiliser le plus récent mono de branche maître, parce que ce problème peut être reproduit sur les anciennes versions de mono (par exemple tarball du 22 Avril est à l'origine de la même exception ).
Edit 2: Ce qui est sans doute vraiment nécessaire pour obtenir ce travail est mise en place valide élément machineKey dans le fichier web.config. Les clés peuvent être générés par exemple par ce utilitaire.