如何阻止ASP.Net网站在向前/向后浏览分页的项目列表时抛出HttpUnhandledException异常?

如何阻止ASP.Net网站在向前/向后浏览分页的项目列表时抛出HttpUnhandledException异常?,asp.net,exception,httpunhandledexception,Asp.net,Exception,Httpunhandledexception,我有一个ASP.Net托管的网站,它将结果列表显示为带有结果分页的DataGrid或ASP.Net Repeater 如果按“上一页/下一页”选项卡快速滚动页面,有时会引发HttpUnhandledException,并呈现调试页面,而不是下一个结果列表 调试屏幕如下所示: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> Sys

我有一个ASP.Net托管的网站,它将结果列表显示为带有结果分页的DataGrid或ASP.Net Repeater

如果按“上一页/下一页”选项卡快速滚动页面,有时会引发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)
System.Web.HttpUnhandledException:引发了类型为“System.Web.HttpUnhandledException”的异常。-->System.ArgumentException:回发或回调参数无效。在配置或页面中使用启用事件验证。出于安全目的,此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件。如果数据有效且符合要求,请使用ClientScriptManager.RegisterForEventValidation方法注册回发或回调数据以进行验证。
位于System.Web.UI.ClientScriptManager.ValidateEvent(字符串唯一标识,字符串参数)
位于System.Web.UI.Control.ValidateEvent(字符串uniqueID,字符串eventArgument)
位于System.Web.UI.WebControl.LinkButton.RaisePostBackEvent(String eventArgument)
位于System.Web.UI.WebControl.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串事件参数)
位于System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)
位于System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
在System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
---内部异常堆栈跟踪的结束---
位于System.Web.UI.Page.HandleError(异常e)
在System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
在System.Web.UI.Page.ProcessRequest(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
在System.Web.UI.Page.ProcessRequest()中
位于System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext上下文)
在System.Web.UI.Page.ProcessRequest(HttpContext上下文)中
在ASP.contacts\u default\u aspx.ProcessRequest(HttpContext上下文)
在System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()中
在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)
我在一次会议上发现了这样一个错误

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


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

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

在页面指令中,可以在页面指令中设置enableEventValidation=false以将其关闭

最后,我相当肯定这个问题最近在Service Pack或3.5中得到了解决

--编辑--

我刚刚找到了设置:

据了解,MSDN在以下版本中受支持:3.5 SP1、3.0 SP2、2.0 SP2