Reputation: 19820
The scenario is following:
The user is wondering why the session has expired during the long running request.
How to tell ASP.NET not to expire session during the request? (To start counting the session timeout after the request is completed.)
UPDATE: The solution should work without JavaScript.
Upvotes: 2
Views: 3122
Reputation: 26766
You could manually extend the session timeout for the particular session by setting the HttpSessionState.Timeout value during report generation (possibly multiple times).
This does seem a little clunky, however, assumes you'd always be able to know in advance how long to increase it by, and you'd need to make sure you set it back afterwards or you'd end up with visitors who've generated a report having different timeouts to those who haven't
While this might work, it's certainly not the best approach and you really should have this run as an asynchronous task.
Upvotes: 0
Reputation: 218877
A web application should respond to requests in a timely manner. I would argue that the actual problem isn't that the session is timing out, it's that a long-running process is happening in-line when it should be off-loaded to the back-end.
Instead of making the user wait for the report, kick off a process on the server to generate the report and respond to the user with a response indicating that their requests has been queued and is being processed, and that their report will be ready when the process is complete.
The user can then continue to navigate the website, use the application, etc. When the report is done, there are various ways you can notify the user. The application can send them an email, perhaps even with the report attached. Or there can be some in-application notification system (like the Facebook notifier) which would either have an AJAX polling mechanism or (in response to your update about not using JavaScript) could be more passive and simply notify them on their first page request following the completion of the report.
In any event, any process which takes this long shouldn't be in-line in a web application.
Edit: As a proposed setup, you could do the following:
Upvotes: 5
Reputation: 2775
What does take long time, the generation of the report or the download of the file? If the operation take to much time you'll probably get an page timeout, your method took too long to respond.
If the session expire because the file requested from the user takes to long to download, then this is a normal behaviour. The user request the file and he looks non active until the next request, the session doesn't get refreshed and it expires.
Upvotes: 0