ASP.NET:获取所有当前/正在运行的请求并直接中止/停止请求
上下文:我们有一个非常大的 ASP.NET Web 窗体应用程序,一些页面/模块非常“重”,需要很长时间来处理此请求。所以问题是,当您误点击错误的菜单来加载页面时,您将不得不等待很长时间。解决方案是刷新浏览器(F5,或更改 URL),但我是对的,服务器仍在处理其请求直到某个时间?
在我们的应用程序中使用 F5 的更多问题是我们没有保留所有状态(大量 iframe 等),因此用户需要重新开始。
我的理想情况是:从所有当前/正在运行的请求中获取一个列表,并中止您想要直接停止处理的请求。 (这甚至可能吗?如果它位于代码块的中间怎么办?它可以终止线程或其他东西吗?我需要 IIS 吗?)
我已经尝试过使用自定义 HttpHandler 来保存所有 HttpContext 对象的列表。这会起作用,但可能不是最好的解决方案。为了停止请求,我尝试了 Response.End() 但随后我得到一个完整的白屏,是否有更好的方法来选择性中止请求?
Context: We have a very large ASP.NET Web Forms application and some pages/modules are very 'heavy' and it takes very long time to process this request. So the problem is when you misclick on the wrong menu to load a page you'll have to wait a long time for nothing. A solution is to refresh de browser (F5, or change URL) but I'm I right that de server is still processsing its request till a certain time?
The more problem with F5 in our application is that we don't preserve all states (lots of iframes etc) so the user needs to start over again.
My ideal situation would be: get a list from all current/running requests and abort the one you want to stop directly from processing. (is this even possible? what if its in the middle of a code block, can it terminate a thread or something? Do I need IIS?)
I've tried something with a custom HttpHandler that holds a list for all HttpContext objects. That will work but isn't probably the best solution. And for stopping a request i've tried Response.End() but then I get a complete white screen, are there better ways to selectivly abort a request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以检查
HttpResponse.IsClientConnected
,如果false
则结束处理,检查该标志为true
的条件以确保它适用于您 http://msdn.microsoft.com/en-我们/library/system.web.httpresponse.isclientconnected.aspxYou can check
HttpResponse.IsClientConnected
and end the processing iffalse
, check the conditions under which the flag istrue
to make sure it will work for you http://msdn.microsoft.com/en-us/library/system.web.httpresponse.isclientconnected.aspx