首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何阻止ASP.Net网站在向前/向后浏览分页列表项目时抛出HttpUnhandledException异常?

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

Stack Overflow用户
提问于 2008-12-02 17:42:51
回答 1查看 47.5K关注 0票数 5

我有一个ASP.Net托管的网站,其中显示的结果作为DataGrid或ASP.Net转发器与结果分页的列表。

如果用户通过按下Previous/Next选项卡快速滚动页面,有时会抛出HttpUnhandledException并呈现调试页面,而不是显示下一个结果列表。

调试屏幕如下所示:

代码语言:javascript
复制
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控件添加代码。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2008-12-02 18:55:25

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

在你的页面指令中,你可以在页面指令中加入enableEventValidation=false来关闭它,however that may not be desirable

You can move the write code to move the elements to the top of the page

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

-编辑--

我刚刚找到了设置:RenderAllHiddenFieldsAtTopOfForm

支持MSDN的版本有: 3.5 SP1、3.0 SP2、2.0 SP2

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/334807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档