如何在请求发送后停止加载页面?

发布于 2024-09-12 07:58:50 字数 124 浏览 2 评论 0原文

我有一个 ASP.NET (C#) 页面,加载时间较长(例如 2 分钟)。用户会看到一个小动画和一条“请稍候”消息。如果用户意外加载此页面,则需要等待其加载。

我的问题是:有没有办法停止页面加载?

谢谢

I have an ASP.NET (C#) page that has a long load time (like 2 minutes). The user is presented with a little animation and a "please wait" message. If the user accidentally loads this page, they need to wait for it to load.

My question is: Is there a way to stop the page load?

Thank you

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

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

发布评论

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

评论(2

水溶 2024-09-19 07:58:50

如果您想停止服务器端处理,那么这是一个棘手的操作。通常,一旦发出请求,该页面就会独立于其他正在发生的事情而独立呈现。您可能需要做的是重新设计该页面,以定期检查是否已发出停止命令并中止此时正在执行的任何操作。停止标志可以在会话中设置,并且应该在停止后清除。

您可能还需要考虑如何正确识别要停止的正确的一个(以防有多个运行)。这可以通过返回一个唯一 ID 来完成,该 ID 可在“中止”页面调用的一部分中使用。

不过,我的方法不是这种复杂的废话,而是努力阻止用户发生这种事故。可能使他们点击的任何链接都会弹出一个警报,提示“以下页面将需要几分钟的时间才能呈现,您是否希望继续”,然后希望您能够在页面请求发出之前有效地中止页面请求。

我应该指出,我以前从未尝试过做这种事情,所以可能有更简单的方法来做到这一点,但这就是我可能想到的解决问题的方式。

If you want to stop the server side processing then its a tricky operation. Generally once a request is made that page is rendering on its own independant of other thigns going on. What you would probably need to do is re-engineer that page to check at regular intervals whether a stop command has been issued and abort whatever it is doing at that point. The stop flag could be put in session and should be cleared out after the stoppage.

You may also need to consider how to properly identify the right one to stop (in case there is more than one running). This could be done by returning a unique ID that can be used in part of a call to the "abort" page.

My approach though rather than this complciated rigmarole is to make efforts to stop the user from making this accident. Possibly make whatever link they are clicking pop up an alert saying "the following page will take several minutes to render, do you wish to continue" and then hopefully you will effectively be aborting the page request before it is even made.

I should note that I've never tried to do this sort of thing before so there may be easier ways to do it but this is how I'd probably think abotu going about the problem.

独夜无伴 2024-09-19 07:58:50

尝试在 JavaScript 中使用 window.stop()

Try window.stop() in JavaScript.

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