Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch data from server without extending session timeout

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.

like image 835
Brian Beckett Avatar asked Jan 13 '11 19:01

Brian Beckett


2 Answers

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.

like image 140
Shan Plourde Avatar answered Sep 21 '22 21:09

Shan Plourde


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.

like image 44
Chandu Avatar answered Sep 21 '22 21:09

Chandu