回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true"...

本文探讨了ASP.NET中出现的“回发或回调参数无效”的异常情况,并提供了多种解决方案,包括禁用事件验证、调整页面加载逻辑等,旨在帮助开发者理解和解决这类问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(转)

回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回 调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

错误:

回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。 

异 常详细信息: System.ArgumentException: 回发或回调参数无效。在配置中使用 < pages enableEventValidation="true"/> 或在页面中使用 <% @ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数 是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。

发生条件:
1。画面有隐藏控件。
2。多次的GRID绑定。

发生原因:
.NET基于页面中的输出元素会在最终页面中生成一个__EVENTVALIDATION隐藏字段。做了一个简单的测试。页面中创建一个<asp: button id="btnSubmit" runat="server" text="Submit" tooltip="Submit" />,同时创建对应的Click事件处理程序。运行程序,可以正确响应事件。然后设置btnSubmit.Visable=false,手动在页面 上面添加<input type="submit" name="btnSubmit" value="Submit" />。运行程序,会出现一个包含EnableEventValidation内容的异常。设置<@Page EnableEventValidation="false">再运行程序,又可以正确响应事件。观察前后两次__EVENTVALIDATION 的内容,可以发现是不同的。关于出现的异常,可以认为在输出的时候没有包含btnSubmit,可是再提交到后台的时候却有相应的内容,前后不一致,所以 在开启事件校验的情况下.NET抛出了异常。

解决办法1:
Page_Load(object sender, EventArgs e) 

if (!Page.IsPostBack) 

//绑定数据; 



解决办法2:
<pages enableEventValidation="false"/>

回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/>

可能出现的问题: 
回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。 
英文描述 
id 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 valida 

可行的解决方法有: 

1、在页面的<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 中添加 EnableEventValidation="false" 就可以了。(首先考虑的) 

2、通过web.config 
<system.web> 
<pages enableEventValidation="false"/> 

3、是Form嵌套,一个页面只能有一个Form,仔细检查代码就可以解决。 

4、如果页面含有 DropDownList 或 ListBox这样的控件,可能以下原因造成: 

4.1 在下拉菜单中使用ajax,常见于省市联动菜单,可能是由于在aspx页面赋给了下拉菜单初始Item值,在事件回发时提示该错误,将下拉菜单初始Item值删除,在绑定事件中添加Item项。 
4.2 原因是 DropDownList 控件的ListItem 的Value 属性 包含汉字.只要将Value 改为英文或数字的就行了.最好在web.config中添加如下语句: 
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="zh-CN" uiCulture="zh-CN"/>因为 POSTBACK 如果不采用 UTF-8 编码, JAVASCRIPT 会认为有问题。 
只改 requestEncoding="utf-8" 就可以了,responseEncoding="utf-8" 不用 

5.Register For Event Validation 
其原理就是让asp.net记录这个postback value. 
RegisterForEventValidation必须在render时调用.

这个要具体分析。本来这个措施是asp.net2.0用来防止客户端“欺诈”服务器端的。例如本来输出到客户端的一个事件被触发时需要回发的命令是“__doPostback( 'ctl01$abc ', 'user_1 ')”的,如果采取采取手段把回发参数由   user_1   改为   user_5   了,服务器端会重新核对输出的是不是user_5,发现和这个页面上一个输出的脚本不一致,就会产生这个异常。 

但是,很多程序员写的程序按照过去的习惯(或者按照更加高级灵活的设计例如一些Ajax组件)没有考虑这个问题或者是忽略这个欺诈的可能性,写的程序可能会修改参数或者修改目标控件。 

因此这样具体问题具体分析。不太可能跟浏览器距离服务器的远近有关,应该还是编程逻辑问题。你应该对出异常的画面以及所使用的数据进行分析。有时候,经常也需要将这个参数设置为false,放弃安全管理。

转载于:https://www.cnblogs.com/weiqt/articles/2104200.html

只有web.config:内容如下哪里是提高画面质量的选项:<?xml version="1.0" encoding="UTF-8"?> <configuration> <!-- CAUTION! logging requires the ASP.NET IIS worker process to have write permission to the "log" folder. Among other options, you may grant the myrtille application pool ("IIS AppPool\MyrtilleAppPool") write permission to it (normally automatically set by the myrtille installer). --> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Log4net" /> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <section name="Myrtille.Web.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </sectionGroup> </configSections> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.5.1.25624" newVersion="1.5.2.14234" /> </dependentAssembly> </assemblyBinding> </runtime> <log4net> <root> <level value="DEBUG" /> <appender-ref ref="LogFileAppender" /> </root> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="log\Myrtille.Web.log" /> <param name="AppendToFile" value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="10MB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> </layout> </appender> </log4net> <system.diagnostics> <trace autoflush="true" indentsize="4"> <listeners> <add name="Log4netTraceListener" type="Myrtille.Log.Log4netTraceListener, Myrtille.Common"> <!-- trace level (Information, Warning or Error). CAUTION! Information level will hinder performance --> <filter type="Myrtille.Log.Log4netTraceFilter, Myrtille.Common" initializeData="Error" /> </add> <!-- disable output window traces. CAUTION! enabling the default output window will hinder performance --> <remove name="Default" /> </listeners> </trace> <!-- enable the lines below for WCF tracing (caution as it will hinder performance). Use SvcTraceViewer.exe as viewer --> <!-- <sources> <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> <listeners> <add name="xml" /> </listeners> </source> <source name="System.ServiceModel.MessageLogging"> <listeners> <add name="xml" /> </listeners> </source> </sources> <sharedListeners> <add initializeData="log\Myrtille.Web.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xml" /> </sharedListeners> --> </system.diagnostics> <system.web> <compilation defaultLanguage="C#" targetFramework="4.5" /> <!-- handle file upload/download up to 1GB. maxRequestLength is measured in kilobytes and executionTimeout in seconds --> <!-- handle querystrings up to 32KB (default 2KB). this can prove useful with large XHRs in HTML4 mode --> <httpRuntime requestValidationMode="4.5" targetFramework="4.5" maxRequestLength="1048576" maxQueryStringLength="32768" executionTimeout="360000" /> <pages enableViewState="false" validateRequest="false" enableEventValidation="false" clientIDMode="AutoID" /> <authorization> <allow users="*" /> </authorization> <authentication mode="None" /> <!-- CAUTION! cookieless="UseUri" allows multiple connections/tabs but, as the http session id is passed into the url, it also implies a risk of session spoofing to mitigate that risk, an authentication cookie is stored into the browser initiating the http session; any other client accessing the http session without it will be rejected please note that, even if the http session is cookieless, this mechanism requires cookies to be enabled client side the "cookieless=" attribute is really confusing because it's in fact the method used by the browser to send the http session id... and using a cookie is the standard way to do it if using myrtille within iframe(s) on a same page, cookieless="UseUri" must be used --> <sessionState mode="InProc" cookieless="UseUri" timeout="60" /> <!--<sessionState mode="InProc" cookieless="UseCookies" cookieName="AuthSecToken" timeout="60"/>--> <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" uiCulture="auto" /> </system.web> <system.webServer> <defaultDocument> <files> <clear /> <add value="Default.aspx" /> </files> </defaultDocument> <urlCompression doDynamicCompression="false" /> <staticContent> <mimeMap fileExtension=".webp" mimeType="image/webp" /> </staticContent> <security> <requestFiltering> <!-- handle file upload/download up to 1GB. maxAllowedContentLength is measured in bytes --> <!-- handle querystrings up to 32KB (default 2KB). this can prove useful with large XHRs in HTML4 mode --> <requestLimits maxAllowedContentLength="1073741824" maxQueryString="32768" /> </requestFiltering> </security> <handlers> <add path="/handlers/SocketHandler.ashx" verb="*" name="SocketHandler" type="Myrtille.Web.SocketHandler" /> <add path="/handlers/AudioSocketHandler.ashx" verb="*" name="AudioSocketHandler" type="Myrtille.Web.AudioSocketHandler" /> <add path="/handlers/EventSourceHandler.ashx" verb="*" name="EventSourceHandler" type="Myrtille.Web.EventSourceHandler" /> <add path="/handlers/LongPollingHandler.ashx" verb="*" name="LongPollingHandler" type="Myrtille.Web.LongPollingHandler" /> </handlers> </system.webServer> <system.serviceModel> <client> <endpoint address="http://localhost:8080/Myrtille/RemoteSessionProcess" binding="wsDualHttpBinding" bindingConfiguration="wsDualHttpBindingCallback" contract="Myrtille.Services.Contracts.IRemoteSessionProcess" /> <endpoint address="http://localhost:8080/Myrtille/FileStorage" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingFileStream" contract="Myrtille.Services.Contracts.IFileStorage" /> <endpoint address="http://localhost:8080/Myrtille/PrinterService" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingFileStream" contract="Myrtille.Services.Contracts.IPrinterService" /> <endpoint address="http://localhost:8080/Myrtille/MFAAuthentication" binding="basicHttpBinding" contract="Myrtille.Services.Contracts.IMFAAuthentication" /> <endpoint address="http://localhost:8080/Myrtille/EnterpriseService" binding="basicHttpBinding" contract="Myrtille.Services.Contracts.IEnterpriseService" /> <endpoint address="http://localhost:8080/Myrtille/ApplicationPoolService" binding="basicHttpBinding" contract="Myrtille.Services.Contracts.IApplicationPoolService" /> </client> <bindings> <wsDualHttpBinding> <binding name="wsDualHttpBindingCallback" receiveTimeout="infinite" maxReceivedMessageSize="2147483647"> <security mode="None" /> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <reliableSession inactivityTimeout="infinite" /> </binding> </wsDualHttpBinding> <basicHttpBinding> <!-- buffer size: 64KB; max file size: 1GB --> <binding name="basicHttpBindingFileStream" transferMode="Streamed" messageEncoding="Mtom" maxBufferSize="65536" maxReceivedMessageSize="1073741824" closeTimeout="infinite" openTimeout="infinite" receiveTimeout="infinite" sendTimeout="infinite"> <security mode="None" /> </binding> </basicHttpBinding> </bindings> <!-- enable the lines below for WCF tracing (caution as it will hinder performance). Use SvcTraceViewer.exe as viewer --> <!-- <diagnostics> <messageLogging logEntireMessage="true" maxMessagesToLog="300" logMessagesAtServiceLevel="true" logMalformedMessages="true" logMessagesAtTransportLevel="true" /> </diagnostics> --> </system.serviceModel> <applicationSettings> <Myrtille.Web.Properties.Settings> <setting name="ConnectionServiceUrl" serializeAs="String"> <value>http://localhost:8008/MyrtilleAdmin/ConnectionService/</value> </setting> </Myrtille.Web.Properties.Settings> </applicationSettings> <appSettings> <!-- disable Visual Studio SignalR --> <add key="vs:EnableBrowserLink" value="false" /> <!-- disable Visual Studio Page Inspector --> <add key="PageInspector:ServerCodeMappingSupport" value="Disabled" /> <!-- providing access to the remote clipboard could be a security issue, it can be disabled below --> <add key="AllowRemoteClipboard" value="true" /> <!-- allow file transfer (requires a domain to be specified on connect) --> <add key="AllowFileTransfer" value="true" /> <!-- allow print download (through a pdf virtual printer). requires the "Myrtille PDF" printer to be installed --> <add key="AllowPrintDownload" value="true" /> <!-- allow remote session sharing (the session is broadcasted to all guests; read/write access is granted individually) --> <add key="AllowSessionSharing" value="true" /> <!-- allow audio plaback --> <add key="AllowAudioPlayback" value="true" /> <!-- share a session by url, with owner rights. set to false to disable and provide a session url spoofing protection. requires cookieless="UseUri" session state (system.web/sessionState section above) --> <!-- if a session is shared by url between different clients, each client is identified by a unique key instead of the http session id --> <add key="AllowShareSessionUrl" value="true" /> <!-- client ip protection --> <add key="ClientIPTracking" value="false" /> <!-- if the browser window/tab of the remote session owner is closed without disconnecting first, or if the connection is lost, delay (ms) before the remote session is disconnected by the gateway. value must be greater than "browserPulseInterval" defined into config.js (default 10 secs). 0 to disable --> <!-- this comes in addition but does not replace the session idle timeout, defined at the RDS level, which will disconnect the session after no user inputs are received for a given time, independently of Myrtille --> <add key="ClientIdleTimeout" value="0" /> <!-- audio buffer. improves the audio quality at the expense of a slight latency --> <add key="AudioBuffering" value="true" /> <!-- show or hide the toolbar (you can hide it if using your own UI) --> <add key="ToolbarEnabled" value="true" /> <!-- connect from a login page or url (you can disable it if using a connection API) --> <add key="LoginEnabled" value="true" /> <!-- if login is enabled, url of the login page (change it if using your own page or leave empty to use the default page) --> <add key="LoginUrl" value="" /> <!-- recycle the application pool when there is no active remote session; not applicable if using the enterprise mode --> <add key="IdleAppPoolRecycling" value="false" /> </appSettings> </configuration>
最新发布
07-20
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Hotel.WebForm1" EnableEventValidation="false" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <link rel="stylesheet" href="Assets/Libraries/Bootstrap/css/bootstrap.min.css" /> <style> body{ background-image:url(../Assets/Images/hotel4.jpg); background-size:cover; } .container-fluid{ opacity:0.9; } </style> </head> <body> <form id="form1" runat="server" > <div> <div class="container-fluid"> <div class="row" style="height:200px"></div> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4 bg-light rounded-3"> <h1 class="text-text-success text-center">皇家理工度假酒店</h1> <form> <div class="mb-3"> <label for="UserTb" class="form-label">用户名</label> <input type="text" class="form-control" id="UserTb" runat="server" required="required"> </div> <div class="mb-3"> <label for="PasswordTb" class="form-label">密码</label> <input type="password" class="form-control" id="PasswordTb" runat="server" required="required"> </div> <div class="mb-3"> <label id="ErrMsg" class="text-danger" runat="server"></label> <input type="radio" id="AdminCb" runat="server" name="Role"><label class="text-success">管理员</label> <input type="radio" id="UserCb" runat="server" name="Role"><label class="text-success">用户</label> </div> <div class="d-grid"> <asp:Button ID="LoginBtn" runat="server" Text="登陆" class="btn btn-success btn-block" OnClick="LoginBtn_Click" /> </div> <br /> </form> </div> <div class="col-md-4"></div> </div> </div> </div> </form> </body> </html>我在form中添加了align=center属性但是删除后却依旧运行了原先配置
05-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值