回发或回调参数无效。事件验证已启用... - 仅在 IIS 10 Selenium 测试下
Invalid postback or callback argument. Event validation is enabled... - Under IIS 10 Selenium testing only
我正在努力解决一个只在特定情况下才会发生的非常奇怪的问题。
我们正在将网络托管环境从 win 2012 IIS 8 升级到 win 2019 IIS 10。我们在 .NET Framework 4.7.2 和 运行 CLR 4.0 版集成下构建了网络应用程序。
我有很多使用 Selenium 运行的自动化测试(Selenium.WebDriver nuget 包 3.141)。我们的其中一个页面能够根据其显示的形式换出它使用的母版页。测试在我们现有的环境中运行良好。其他形式也可以正常工作。
但是,在新的 IIS 10 环境中,对于一个特定的母版页,并且只针对这个特定的表单页,如果:
- Selenium 发布页面(通过提交按钮)
- 它 returns 有验证错误
- Selenium 然后使用有效或无效数据通过同一个按钮第二次发布它
- 页面因以下错误而崩溃:
ERROR LEVEL 1
HttpUnhandledException -> Exception of type 'System.Web.HttpUnhandledException' was thrown. StackTrace: 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.ProcessRequest(HttpContext context) at
ASP.plt_pltgeneral_aspx.ProcessRequest(HttpContext context) in
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\roota5c1fe\a330c9cd\App_Web_w4e2wdui.14.cs:line 0 at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
ERROR LEVEL 2
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. StackTrace:
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.DropDownList.LoadPostData(String
postDataKey, NameValueCollection postCollection) at
System.Web.UI.Page.ProcessPostData(NameValueCollection postData,
Boolean fBeforeLoad) at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
如果通过手动测试以相同的顺序提交相同的表单,它就可以正常工作。但是,如果您通过 selenium 启动浏览器,然后暂停测试并手动完成序列,它仍然会崩溃。因此,Selenium、IIS 10、第二次回发的页面以及这个特定的母版页的组合有些东西。
我目前的理论是,由于这一切都在现有环境中有效,因此 IIS 10 中的事件验证方式一定发生了一些变化。在两种环境中都是相同的代码 运行。
我正在寻找 theories/fixes 为什么 IIS 升级会触发这个非常具体的问题,以及可能触发它的原因,以便我可以解决它。
编辑:
我已将问题追溯到一个旧的隐藏下拉列表:
<div style="float: right; position: relative; visibility: hidden;" class="nav2">
<asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="true" Visible="false" EnableViewState="false" OnSelectedIndexChanged="ddlCountry_OnSelectedIndexChanged" />
</div>
呈现为 HTML:
<div style="float: right; position: relative; visibility: hidden;" class="nav2">
<select name="ctl00$ddlCountry" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ddlCountry\',\'\')', 0)" id="ctl00_ddlCountry">
<option value="All">All</option>
<option selected="selected" value="1">United States</option>
如果我修改包装 div 使其不呈现:
<div style="float: right; position: relative; visibility: hidden;" class="nav2" runat="server" Visible="false">
然后问题就解决了。
在这种情况下,这对我来说是一个很好的解决方案,因为无论如何这都会清除旧代码。但是,仍然感觉 IIS 中发生了一些变化(可能已修复),导致其行为不同。
问题最终是 .net 呈现的隐藏 DropDownList 控件,即使它被设置为不可见。删除旧代码后,问题就解决了。
我最好的猜测是这里有两个错误。呈现应该不可见的控件的 .net 错误。还有一个新的 IIS 10/CLR 错误,它不会忽略对不可见控件的更改。
这两个潜在的错误加上可能被 selenium 修改的不可见控件可能已经全部合并在一起,为我创建了这个场景。
我正在努力解决一个只在特定情况下才会发生的非常奇怪的问题。
我们正在将网络托管环境从 win 2012 IIS 8 升级到 win 2019 IIS 10。我们在 .NET Framework 4.7.2 和 运行 CLR 4.0 版集成下构建了网络应用程序。
我有很多使用 Selenium 运行的自动化测试(Selenium.WebDriver nuget 包 3.141)。我们的其中一个页面能够根据其显示的形式换出它使用的母版页。测试在我们现有的环境中运行良好。其他形式也可以正常工作。
但是,在新的 IIS 10 环境中,对于一个特定的母版页,并且只针对这个特定的表单页,如果:
- Selenium 发布页面(通过提交按钮)
- 它 returns 有验证错误
- Selenium 然后使用有效或无效数据通过同一个按钮第二次发布它
- 页面因以下错误而崩溃:
ERROR LEVEL 1
HttpUnhandledException -> Exception of type 'System.Web.HttpUnhandledException' was thrown. StackTrace: 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.ProcessRequest(HttpContext context) at ASP.plt_pltgeneral_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\roota5c1fe\a330c9cd\App_Web_w4e2wdui.14.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)ERROR LEVEL 2
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. StackTrace:
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.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection) at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
如果通过手动测试以相同的顺序提交相同的表单,它就可以正常工作。但是,如果您通过 selenium 启动浏览器,然后暂停测试并手动完成序列,它仍然会崩溃。因此,Selenium、IIS 10、第二次回发的页面以及这个特定的母版页的组合有些东西。
我目前的理论是,由于这一切都在现有环境中有效,因此 IIS 10 中的事件验证方式一定发生了一些变化。在两种环境中都是相同的代码 运行。
我正在寻找 theories/fixes 为什么 IIS 升级会触发这个非常具体的问题,以及可能触发它的原因,以便我可以解决它。
编辑:
我已将问题追溯到一个旧的隐藏下拉列表:
<div style="float: right; position: relative; visibility: hidden;" class="nav2">
<asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="true" Visible="false" EnableViewState="false" OnSelectedIndexChanged="ddlCountry_OnSelectedIndexChanged" />
</div>
呈现为 HTML:
<div style="float: right; position: relative; visibility: hidden;" class="nav2">
<select name="ctl00$ddlCountry" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ddlCountry\',\'\')', 0)" id="ctl00_ddlCountry">
<option value="All">All</option>
<option selected="selected" value="1">United States</option>
如果我修改包装 div 使其不呈现:
<div style="float: right; position: relative; visibility: hidden;" class="nav2" runat="server" Visible="false">
然后问题就解决了。
在这种情况下,这对我来说是一个很好的解决方案,因为无论如何这都会清除旧代码。但是,仍然感觉 IIS 中发生了一些变化(可能已修复),导致其行为不同。
问题最终是 .net 呈现的隐藏 DropDownList 控件,即使它被设置为不可见。删除旧代码后,问题就解决了。
我最好的猜测是这里有两个错误。呈现应该不可见的控件的 .net 错误。还有一个新的 IIS 10/CLR 错误,它不会忽略对不可见控件的更改。
这两个潜在的错误加上可能被 selenium 修改的不可见控件可能已经全部合并在一起,为我创建了这个场景。