ASP.Net:浏览器断开连接时如何停止页面执行?
如果浏览器请求 ASP.Net 页面,然后用户单击“停止”或导航离开,我认为浏览器将关闭连接,ASP.Net 可能会停止执行。我认为情况并非如此,因为当我测试这个时,没有调用 Dispose() 。是否有办法知道浏览器/客户端何时断开连接,然后停止页面执行?
If a browser requests an ASP.Net page and then the user clicks "stop" or navigates away, I thought that the browser would close the connection and ASP.Net would perhaps stop execution. I don't think that's the case since Dispose() is not called when I test this. Is there anyway to know when the browser/client has disconnected and then stop the page from executing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚遇到这个非常古老的问题。
现在有一个巧妙的解决方案。从 .NET 4.5 开始,当客户端断开连接时,您实际上可以异步收到通知。
这意味着您可以终止长时间运行的 sql 查询。
操作方法如下:
I just came across this very old question.
There is a neat solution now. Since .NET 4.5 you can actually get notified asynchroneously when the client disconnects.
This means that you can kill the long-running sql query.
Here's how to do it:
您可以检查
IsClientConnected
You can check the
IsClientConnected