简体   繁体   English

页面事件验证失败发生在一种环境中,而在另一种环境中不发生

[英]Page Event Validation failure happens in one environment, but not the other

I am getting a rather standard event validation error under a particular set of steps with our web app: 在我们的网络应用程序的一组特定步骤下,我收到了一个相当标准的事件验证错误:

Application_Error intercepted exception: Exception of type 'System.Web.HttpUnhandledException' was thrown.
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.

The real headscratcher is that this is happening in our test environment, but not my development environment when I try to re-create. 真正的难题是,这是在我们的测试环境中发生的,而不是在我尝试重新创建时在我的开发环境中发生的。 I've perused our web.config for things that might have changed, but I don't see anything that jumps out. 我仔细研究了web.config中可能发生的更改,但是我看不到任何跳出的内容。 The code is completely the same between the environments - TeamCity made certain of that. 环境之间的代码完全相同-TeamCity对此进行了确认。 So I'm strongly suspecting an environmental problem, but I have little idea of where to start with something like event validation. 因此,我强烈怀疑环境问题,但对于事件验证之类的方法从何处入手,我一无所知。 That is typically handled in code. 通常用代码处理。

Does anyone have an idea for a path to investigate on this? 有没有人想办法对此进行调查? I realize some of the details of what I'm doing are sparse, but that is because everything works 100% fine in our development environments and there are no issues at all, so I don't know what would be relevant and what wouldn't. 我意识到我正在做的事情的细节很稀疏,但这是因为在我们的开发环境中一切都可以100%正常地工作,并且根本没有问题,所以我不知道什么是有意义的,什么不是。吨。 If more details are required, please ask and I will be delighted to provide them. 如果需要更多详细信息,请询问,我们将很高兴为您提供。

Presumably you've checked the enableEventValidation attribute in your config file - by default this won't exist. 大概您已经检查了配置文件中的enableEventValidation属性-默认情况下该属性不存在。 But it could very well be in the machine.config on one or both machines, resulting in a different configuration for that option. 但是它很可能位于一台或两台计算机上的machine.config中,从而导致该选项的配置不同。

For posterity, this was the situation. 对于后代,情况就是这样。

We have a few dropdown lists that are populated via information from the HTTPWebSession cache. 我们有一些下拉列表,这些列表是通过HTTPWebSession缓存中的信息填充的。 Great. 大。 We also have an AJAX partial postback at one point during our work flow, because we have to do some server side validation of user input without screwing up everything on the screen. 在我们的工作流程中,我们还会在某一时刻进行AJAX部分回发,因为我们必须对用户输入进行服务器端验证,而又不会弄乱屏幕上的所有内容。 Still no problem. 还是没问题。

The problem occurs when this partial postback returns, and attempts to use some CSS classes that link to images that no longer exist in our project. 返回此部分回发并尝试使用一些CSS类链接到我们项目中不再存在的图像时,就会发生问题。 The images were moved. 图像已移动。 This returns 404s. 这将返回404s。 You'd still think this isn't an issue as long as the code isn't actually USING these images. 您仍然会认为这不是问题,只要代码实际上没有使用这些图像即可。 And it's not. 事实并非如此。

The PROBLEM is that, in our testing environments, a 404 is a 404. It simply returns that, no big deal. 问题是,在我们的测试环境中,404是404。它只是返回那,没什么大不了的。 In our production environments, we redirect 404 errors to our login page, because it's a bad user experience and it's not good to implicitly reveal what does and doesn't exist. 在生产环境中,我们将404错误重定向到我们的登录页面,因为这是糟糕的用户体验,并且隐式揭示存在和不存在的内容并不好。 This is the environmental factor. 这是环境因素。

...Because we work in a high-security environment, the login page wipes the cache as part of its PreRender, so it doesn't matter if it was actually loading the page graphics or not. ...由于我们在高度安全的环境中工作,因此登录页面将缓存作为其PreRender的一部分进行擦除,因此实际上是否加载页面图形都无关紧要。 Ergo, an AJAX partial postback wiped the cache, which made the session-loaded information in the dropdown list -- which is not updated by the partial postback! Ergo,一个AJAX部分回发擦除了缓存,这使会话加载的信息出现在下拉列表中-部分回发不会更新该信息! -- not expected input. -不需要输入。 And, perfectly reasonably, Event Validation refused to accept this input on the full page submit. 而且,完全合理地,事件验证拒绝在整页提交中接受此输入。

This strange and complex problem was solved...by deleting a CSS class. 通过删除CSS类,解决了这个奇怪而复杂的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM