响应离开 IIS 后是否会调用 Page Unload?

发布于 2024-12-09 11:36:33 字数 610 浏览 0 评论 0原文

我正在 asp.net 应用程序的 Page_Unload 事件中进行一些诊断日志记录,此日志记录可能需要相当长的时间(大约 100 毫秒)。响应流是否会被页面卸载处理程序中的代码阻止?我可以使用 theadpool 异步完成工作,但如果它不会影响客户端的响应时间,我宁愿不这样做。

更多信息:

@thorkia 是正确的,因为文档说 Page_Unload 在响应发送到客户端后被调用,但在我的测试中(正如@steve建议的),它确实阻止。我尝试过 Casini、IIS Express、Full IIS 7.5(在测试服务器上),无论是否附加了调试器,都包含发布版本和调试版本。并且,抓住救命稻草,我尝试将 Async=true 放入页面指令中。我尝试使用 Fiddler(启用流媒体)和不使用 Fiddler。我已经尝试过 IE9 和 Firefox。如果文档是“正确的”,那么我想知道它确实发送了响应,但可能没有“完成它”(这意味着我需要检查 HTTP 规范),因此页面不会呈现浏览器?但我的理解是,客户端浏览器在收到字节时开始渲染页面,这对我来说也没有意义。我也尝试过查看 IL Spy 中的代码,但我认为这可能会花费我很多时间。

现在我很好奇;我做错了什么,还是文档有误导性?

I'm doing some diagnostic logging in the Page_Unload event in an asp.net application, this logging can take a fair bit of time (about 100ms). Will the response stream get held up by the code in the Page Unload handler? I could do my work asynchronously by using the theadpool but I'd rather not if it won't affect the client's response time.

More information:

@thorkia is correct in that the documentation says that Page_Unload is called after the response is sent to the client, but in my testing (as advised by @steve) it does block. I've tried Casini, IIS Express, Full IIS 7.5 (on a test server) with both release and debug builds, with and without a debugger attached. And, grasping at straws, I tried putting Async=true in the Page Directive. I tried with Fiddler (streaming enabled), and without Fiddler. I've tried with IE9, and Firefox. If the documentation is "correct" then I wonder it it does send the response but perhaps doesn't "finish it off" (what ever that means I'll need to check the HTTP spec) and so the page doesn't render in the browser? But my understanding was that a client browser starts to render the page as it receives the bytes to this doesn't make sense to me either. I've also tried looking at the code in IL Spy but I think this might take me a lot of time.

Now I'm intrigued; am I doing something wrong, or is the documentation misleading?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最美不过初阳 2024-12-16 11:36:33

为什么不尝试一下呢?

protected void Page_UnLoad(object sender, EventArgs e)
{
    System.Diagnostics.Debug.WriteLine("In Page_UnLoad");
    System.Threading.Thread.Sleep(10000);
    System.Diagnostics.Debug.WriteLine("Leaving Page_UnLoad");
}

Why not try it?

protected void Page_UnLoad(object sender, EventArgs e)
{
    System.Diagnostics.Debug.WriteLine("In Page_UnLoad");
    System.Threading.Thread.Sleep(10000);
    System.Diagnostics.Debug.WriteLine("Leaving Page_UnLoad");
}
乖不如嘢 2024-12-16 11:36:33

根据 MSDN (http://msdn.microsoft.com/en-us/library /ms178472.aspx) 只有在数据发送到客户端后才会调用页面卸载阶段。

花费很长时间进行日志记录和清理不会影响客户端对该请求的响应时间,但如果有大量页面等待卸载,则可能会影响将来的请求。

According to MSDN (http://msdn.microsoft.com/en-us/library/ms178472.aspx) the Page Unload stage is only called after the data has been sent to the client.

Taking a long time to do your logging and clean up will not affect the clients response time for that request but could affect future requests if lots of pages are waiting to be unloaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文