ASP.NET 页面加载后调用附加的 aspx 页面
为了简单起见,我们有一些 aspx 页面...
Page1.aspx - 重置会话信息。
Page2.aspx - 搜索包含结果的表单并设置会话变量。
Page3.aspx、Page4.aspx、Page5.aspx - 需要在 Page2.aspx 上设置会话变量
我们发现,当 Page2.aspx 加载并设置会话变量时,Page1.aspx 正在被调用并重置会话。 但是,浏览器中显示的是 Page1.aspx,而不是 Page2.aspx。 当我们单步执行代码并在 Page1.aspx 和 Page2.aspx 的 Page_Load 事件中设置断点时,我们才发现这种情况发生,并且惊讶地发现,一旦 Page1.aspx 停止处理,Page2.aspx 就会被处理。服务器。
可能有用的信息...我们确实使用母版页,并且母版页中有指向 Page1.aspx 的链接。 除此之外,我在代码库中找不到任何对 Page1.aspx 的引用。
更新:
这可能是由于身份验证? 看起来当我访问Page2.aspx时,服务器可能会在Page1.aspx上再次进行身份验证? 这是典型的吗?
To keep things simple, we have a few aspx pages...
Page1.aspx - resets Session information.
Page2.aspx - Search form with results and sets Session variables.
Page3.aspx, Page4.aspx, Page5.aspx - require Session variables set on Page2.aspx
What we're finding is that as Page2.aspx loads and setting the Session variables, Page1.aspx is being called and resetting the Session. However, Page1.aspx shows up in the browser, not Page2.aspx. We were only able to find this happening as we stepped through the code and put break points in the Page_Load events for Page1.aspx and Page2.aspx and were surprised to see Page2.aspx being processed as soon as Page1.aspx stopped processing on the server.
Possibly useful info... we do use a Master page and there are links to Page1.aspx in the Master page. Other than that, I can not find any references to Page1.aspx in the code base.
update:
It may be due to authentication? It appears that when I access Page2.aspx, the server is possibly authenticating again on Page1.aspx? Is that typical?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢安德鲁的提示。
我们弄清楚发生了什么...应用程序中的 Page1.aspx 实际上是 Default.aspx。 在 Page2.aspx 上,另一位开发人员在未定义 src 属性的页面上放置了一个 img 标记。 因此,当执行 Page2.aspx 时,它会查找位于网站根级别的图像,然后触发 Default.aspx (Page1) 上的代码并清除会话。
总的来说,它看起来像这样......
在 Page2.aspx
希望这对其他人有帮助。
Thanks for the tip Andrew.
We figured out what was going on... Page1.aspx in the application is really Default.aspx. On Page2.aspx, another developer put a img tag on the page that did not have src property defined. So when Page2.aspx executed, it was looking for an image located at the web site's root level, this then triggered the code on Default.aspx (Page1) and wipe away the session.
Overall it looked something like this...
On Page2.aspx
Hopefully that helps out someone else.
启动 Fiddler 并正常运行应用程序。 它会告诉您正在发生的流量并确定哪些页面正在重定向到其他页面。 一旦知道了路径,您就可以通过研究源代码来确定该路径存在的原因。
您的应用程序域可能正在回收,因此所有会话变量都会丢失,并且您可能有代码在会话变量丢失时重定向访问者,对吗?
如果是这种情况,作为快速解决方案,您可以使用 StateServer 或将会话变量存储在 Sql Server 中。 您的应用程序域不应每分钟都进行回收,但如果您“正在处理”存储会话(这是默认设置),则可能会导致您看到的行为。
Launch Fiddler and run the application normally. It will tell you the traffic that is occurring and identify what pages are redirecting to other pages. Once you know the path, you can identify why that path exists by investigating the source code.
It's possible that your application domain is recycling and thus, all the session variables are lost and you probably have code the redirects the visitor if the session variables are missing, right?
If this is the case, as quick fix, you can use the StateServer or store your session variables in Sql Server. Your application domain shouldn't be recycling every minute, but it could cause the behavior you see if you're storing sessions "in process", which is the default.