C# ASP.NET MVC:AntiForgeryToken在mono中有效吗?
我试图在Mono(XSP)下的ASP.NET MVC中使用C# ASP.NET MVC:AntiForgeryToken在mono中有效吗?,c#,asp.net-mvc,asp.net-mvc-2,mono,xsp,C#,Asp.net Mvc,Asp.net Mvc 2,Mono,Xsp,我试图在Mono(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 /
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
你知道有什么其他的方法来实现这一点吗
提前谢谢
编辑:这是我的视图代码(它是局部视图)。如果我删除了
行,那么一切都可以正常工作,在其他情况下,它会出现上述异常
<%@ 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>
说:
更新评论
您是否在为POST谓词提供服务的控制器操作上设置了[ValidateAntiForgeryToken]
属性
编辑:此问题的可能解决方案可能是使用master branch的最新mono,因为此问题可以在旧版本的mono上复制(例如,4月22日的tarball导致了相同的异常)
编辑2:可能真正需要的是在web.config文件中设置有效。例如,可以使用实用工具生成密钥。您是否检查过在MS.NET下运行的相同代码?我正在使用AntiForgeryToken在apache上托管的MVC webapp中使用mod_mono,它可以正常工作。你能通过你的视图和控制器代码吗?@Tomi:当然,我正在更新帖子以粘贴视图代码。控制器不是问题,只是在运行时编译视图失败。@Michael,不,我没有在下测试它。NET@Tomi:是的,问题在局部视图中。实际上,如果我从视图中删除
Html.AntiForgeryToken()
,控制器会抛出一个异常(未找到必需的AntiForgeryToken…)。嗯,这看起来很奇怪。你能通过生成的html源代码查看防伪令牌是否存在于你表单下的隐藏字段中吗?@Tommy:知道吗?你在尝试什么版本的Mono?@Daniel:我有Mono 2.9(11月20日从github master下载)。XSP和mod_mono也来自同一日期主分支。你能试着用mod_mono通过apache运行你的webapp吗?你在XSP中运行过吗?我刚刚遇到这个错误消息,想知道这是如何解决的?作为参考,我使用OpenSUSE 11.3、Mono 2.8.1、ASP.NET 4、ASP.NET MVC 2.0和Mono Develop 2.4.2