5

我有一个 ASP.Net 托管网站,它将结果列表显示为 DataGrid 或 ASP.Net 中继器,并带有结果分页。

如果通过按上一个/下一个选项卡快速滚动页面,有时会引发 HttpUnhandledException 并呈现调试页面而不是下一个结果列表。

调试画面如下:

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
  at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument)
  at System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument)
  at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
  at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
  at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
  at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  --- End of inner exception stack trace ---
  at System.Web.UI.Page.HandleError(Exception e)
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  at System.Web.UI.Page.ProcessRequest()
  at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
  at System.Web.UI.Page.ProcessRequest(HttpContext context)
  at ASP.contacts_default_aspx.ProcessRequest(HttpContext context)
  at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

我在http://blogs.msdn.com/amitsh/archive/2007/07/31/why-i-get-invalid-postback-or-callback-argument-errors.aspx找到了对此类错误的引用

但建议的解决方案是设置为 false,但这似乎会造成安全漏洞。评论推荐了几种替代方案,但似乎都相当复杂,因为它们需要向我整个站点中使用的每个 DataGrid 或 Repeater 控件添加代码。

有没有更通用的解决方案可以在不牺牲安全性的情况下完成?

4

1 回答 1

9

回发时未提供页面上的隐藏字段。其中有几个字段,它们通常是 ASP.Net 提供的“魔法”所必需的。

在您的页面指令中,您可以将 enableEventValidation=false 放在您的页面指令中以将其关闭,但这可能是不可取的

您可以移动编写代码以将元素移动到页面顶部

最后,我相当肯定这个确切的问题最近在 Service Pack 或 3.5 中得到修复。

- 编辑 -

我刚刚找到了设置:RenderAllHiddenFieldsAtTopOfForm

根据 MSDN,以下版本支持:3.5 SP1、3.0 SP2、2.0 SP2

于 2008-12-02T18:55:24.957 回答