【发布时间】:2016-02-09 11:54:50
【问题描述】:
当我尝试模拟有人篡改我的表单时,我在应用程序中收到此错误...
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.
我了解它为什么会发生,它保护我免受什么伤害,我希望它保持原位。 我想做的是更好地处理它。显示一条更好的消息来说明您的输入或类似内容存在问题,而不是此 .net 崩溃。
有没有办法可以捕获此异常并在我的 web.config 文件中以与状态错误类似的方式处理它?
例如
<customErrors mode="Off" defaultRedirect="Errors/GenericErrorPage.aspx">
<error statusCode="403" redirect="Errors/NoAccess.htm" />
<error statusCode="404" redirect="Errors/FileNotFound.htm" />
</customErrors>
【问题讨论】:
-
恕我直言,您应该尽可能靠近源头处理它,但始终可以选择handle uncaught exceptions - 只需谷歌即可 - 有很多地方可以将它们连接起来跨度>
-
感谢您的评论和链接。我们在一个长期运行的 webfroms 项目中有很多旧表单,这些表单实际上并没有足够的异常处理......对于这个特定问题,如果能集体处理会很好!
-
向攻击者提供详细的错误消息非常接近不应该做的事情列表的顶部。
-
你是对的 :) 不想透露细节 - 只是想避免崩溃。但是,如果发生了一些不愉快的事情,我宁愿给他们一个漂亮的错误页面也无济于事。