gpt4 book ai didi

c# - 回发或回调参数无效。使用以下方式启用事件验证

转载 作者:行者123 更新时间:2023-11-30 19:09:07 26 4
gpt4 key购买 nike

自从从 2.0 迁移到 .net 4.5.1 后,我遇到了这个错误

Invalid postback or callback argument. Event validation is enabled using 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.

[ArgumentException: Invalid postback or callback argument. Event validation is enabled using 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.]
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +144
System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +111
System.Web.UI.WebControls.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection) +55
System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +16
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +303
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1593

我能做什么?

我在本地主机上有这个问题,但如果我尝试远程访问它,问题就解决了(在另一个工作站上)。如果同事尝试在他的电脑(为我工作的那台电脑)上访问它,他们会遇到同样的问题,但如果他们使用我的工作站,则该应用程序可以正常工作。

最佳答案

我遇到了同样的问题。在我的例子中,问题是因为我在表单标签中插入了 javascript 并且 javascript 正在提交表单。在我将我的解决方案从 .NET 3.5 移至 4.5.1 之前,该代码运行良好多年。在 ASP.NET WebForm 中有一些自动生成的隐藏字段。其中一个字段是 __EVENTVALIDATION 字段,它可以防止发布未经授权的数据(例如从 javascript 向 DropDownList 服务器控件添加额外选项)。

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAN+KgYAJkWoXhOSD3+DUVvd3588JQsnNAC5MN7/uyI1ci6YmP63wnPMGlpCSu3QTgdg0MzSFI9etYOG29clJ48nEH4YX8U9SWslVBX+CGpmog==" />

通常这些隐藏字段是作为表单中的第一个元素生成的。然而,在升级之后,这个元素开始作为表单中的最后一个元素出现,就在我正在提交的 javascript 的下面。因此,此字段未作为请求的一部分发送,服务器将其解释为试图发布未经授权的数据。

经过一番研究,我发现 web.config 中有一个配置,您可以使用它来控制字段的放置:

<system.web>
<pages renderAllHiddenFieldsAtTopOfForm="true" />
</system.web>

然而,这在默认情况下是正确的,所以它没有任何效果。在研究了这个配置并在这里找到了部分答案之后 Why is the renderAllHiddenFieldsAtTopOfForm configuration setting ignored?,我使用了 Resharper + DotPeek + 来自 http://http://referencesource.microsoft.com/ 的代码在 System.Web 程序集内部进行调试。我发现在 Debug模式下,InnerWriter 属性不是 HttpWriter,而是类型 Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.BrowserLinkExecutionListener.PassthroughPositionTracker.PassthroughTextWriter。 PageInspector 功能干扰了页面呈现。

我的解决方案:

通过在 web.config 的 appsettings 部分中插入以下标记来禁用 PageInspector(我根本不需要它):

<appSettings>
<add key="PageInspector:ServerCodeMappingSupport" value="Disabled" />
</appSettings>

这对我有用。更多信息在这里 http://bchavez.bitarmory.com/archive/2012/12/28/rip-page-inspector-out-of-your-web-site-projects-now.aspx

关于c# - 回发或回调参数无效。使用以下方式启用事件验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33479832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com