从服务器获取数据而不延长会话超时

发布于 2024-10-11 14:17:31 字数 296 浏览 4 评论 0 原文

ASP.net 中是否有任何方法可以从服务器获取数据而不延长会话超时?这需要每隔几分钟完成一次,无需用户交互,直到页面关闭。

根据要求提供其他上下文:

我的 web 应用程序中的页面需要每隔几分钟轮询一次服务器以检查特定情况(在本例中,紧急维护计划为 30 分钟)。当条件为真时,页面将向用户显示一条消息。当条件为假时,什么都不需要发生。

据我了解,到服务器的回发会重置时间,直到会话过期。我们不希望每次页面轮询服务器时会话都被扩展/刷新/重置/无论是什么。我需要一种自动轮询服务器而不重置会话超时的方法。

谢谢。

Are there any ways in ASP.net to fetch data from the server without extending the session timeout? This needs to be done every few minutes without user interaction until the page is closed.

Additional context, as requested:

The pages in my webapp needs to poll the server every few minutes to check for a particular condition (emergency maintenance scheduled for 30 minutes time, in this instance). When the condition is true, the page will display a message to the user. When the condition is false, nothing needs to happen.

As I understand it, postbacks to the server reset the time until the session expires. We do not want the session to be extended/refreshed/reset/whatever the word is every time the page polls the server. I need a way to poll the server automatically without resetting the session timeout.

Thanks.

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

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

发布评论

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

评论(3

浅浅 2024-10-18 14:17:31

如果您在较长的 HTTP 请求的上下文中进行询问,以便您希望防止 HTTP 超时,请查看 web.config 的 < /code> 其中executionTimeout以秒为单位我认为, http ://msdn.microsoft.com/en-us/library/e1f13641(v=vs.71).aspx

如果确实只是会话超时问题,是否可以在冗长的进程运行时在同一用户会话下异步 ping 服务器?

编辑
根据您的编辑,如果您将“网站维护”Web 服务划分为网站正常部分的会话状态范围之外的服务,那么您可以根据需要随时调用它。例如,如果您此时在当前网站中使用 ASMX Web 服务,只需将其分区到一个单独的应用程序中,也许作为应用程序之外的目录,以便它属于同一域。我想那会很好。

我不确定您此时调用的 Web 服务类型(ASMX、WCF 等),或者即使您此时调用的 Web 服务与您的 ASPX 应用程序页面位于同一应用程序中。

If you're asking in the context of a lengthy HTTP request, so that you're looking to prevent an HTTP timeout, look at web.config's <httpRuntime executionTimeout="99999"></httpRuntime> where executionTimeout is in seconds I think, http://msdn.microsoft.com/en-us/library/e1f13641(v=vs.71).aspx.

If it is truly just a session timeout issue, is it possible to asynchronously ping the server under the same user session, while the lengthy process is running?

Edit:
Based on your edit, if you partition your "web site maintenance" web service into a service outside of the session state scope of the normal part of the site, then you can call it as often as you'd like. If you're using an ASMX web service in your current website at this time, for example, simply partition it into a separate application, perhaps as a directory off of your application, so that it falls under the same domain. I imagine that would work fine.

I'm not sure what web service type you're invoking at this time (ASMX, WCF, etc.), or even if the web service that you're invoking at this time is in the same application as your ASPX application pages.

遇见了你 2024-10-18 14:17:31

首先,如果查询运行超出会话时间限制,则该查询存在严重问题。我宁愿先修复查询。
但是,如果您仍然想使用会话来执行此操作,请尝试以下操作:

您可以在应用程序中添加一个 Dummy.aspx,然后让图像元素每 15 分钟刷新一次其 URL,如下所示:

<img id="dummyImage" src="/Dummy.aspx" width=0 height=0/>

<script type="text/javascript">
    var dummyImage = document.getElementById("dummyImage");
    setInterval(function(){
        dummyImage.src = "Dummy.aspx?_tmp=" + (Math.random() * 100000);
    }, 900000);
</script>

这样您就不会影响会话超时全球水平。

First, if a query is running beyond the session time limit then there is a serious problem with the query. I would rather fix the query first.
However if you still want to do it using the session, try this:

You can have a Dummy.aspx in your app and then have a image element refresh its URL every 15 minutes like:

<img id="dummyImage" src="/Dummy.aspx" width=0 height=0/>

<script type="text/javascript">
    var dummyImage = document.getElementById("dummyImage");
    setInterval(function(){
        dummyImage.src = "Dummy.aspx?_tmp=" + (Math.random() * 100000);
    }, 900000);
</script>

This way you will not impact the session timeout at a global level.

独闯女儿国 2024-10-18 14:17:31

使用 javascript 计时器来触发 AJAX 调用。因此,在您的 PageLoad 事件中回显 javascript setInterval(functiontocall(), timetowait); 函数。您调用的方法将是对执行您的查询的 Web 服务的 AJAX 命中。

这将不断调用自身,直到用户关闭页面。

会话不会因 AJAX 点击而刷新。

Use a javascript timer which fires an AJAX call. So in your PageLoad event echo out a javascript setInterval(functiontocall(), timetowait); function. The method you call will be the AJAX hit to a web service which does your query.

This will keep calling itself until the user closes the page.

Sessions do not get refreshed from AJAX hits.

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