Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ASP.NET continue reliably processing a request even after a user is navigated away via javascript?

Environment:

  • Windows Server 2003 - IIS 6.x
  • ASP.NET 3.5 (C#)
  • IE 7,8,9
  • FF (whatever the latest 10 versions are)

User Scenario:

User enters search criteria against large data-set. After initiating the request, they are navigated to a results page, where they wait until the data is loaded and can then refine the data.

Technical Scenario:

After user sends search criteria (via ajax call), UI calls back-end service. Back-end service queries transactional system(s) and puts the resulting data into a db "cache" - a denormalized table, set-up for further refining the of the data (i.e. sorting, filtering). UI waits until the data is cached and then upon getting notified that the process is done, navigates to a resulting page. The resulting page then makes a call to get the data from the denormalized table.

Problem:

The search is relatively slow (15-25 seconds) for large queries that end up having to query many systems based on the criteria entered. It is relatively fast for other queries ( <4 seconds).

Technical Constraints:

  1. We can not entirely re-architect this search / results system. There are way to many complexities here between how the UI and the back-end is tied together. The page is required (because of constraints that can not be solved on StackOverflow) to turn after performing the search criteria.

  2. We also can not ask the organization to denormalize the data prior to searching because the data has to be real-time, i.e. if a user makes a change in other systems, the data has to show up correctly if they do a search afterwards.

Process that I want to follow:

  1. I want to cheat a little. I want to issue the "Cache" request via an async HttpHandler in a fire-forget model.

  2. After issuing the query, I want to transition the page to the resulting page.

  3. On the transition page, I want to poll the "Cache" table to see if the data has been inserted into it yet.

  4. The reason I want to do this transition right away, is that the resulting page is expensive on itself (even without getting the data) - still 2 seconds of load time before even getting to calling the service that gets the data from the cache.

Question:

Will the ASP.NET thread that is called via the async handler reliably continue processing even if I navigate away from the page using a javascript redirect?

Technical Boundaries 2:

Yes, I know... This search process does not sound efficient. There is nothing I can do about that right now. I am trying to do whatever I can to get it to perform a little better while we continue researching how we are going to re-architect it.

If your answer is to: "Throw it away and start over", please do not answer. That is not acceptable.

like image 698
Jamie Gunn Avatar asked Feb 11 '13 00:02

Jamie Gunn


People also ask

How does ASP NET core process a request?

The ASP.NET Core web server will convert the response from the application logic into a raw HTTP response and sends it back to the reverse proxy. The reverse proxy will then send it back to the browser.

How does ASP NET core handle multiple requests?

ASP.NET Core apps should be designed to process many requests simultaneously. Asynchronous APIs allow a small pool of threads to handle thousands of concurrent requests by not waiting on blocking calls. Rather than waiting on a long-running synchronous task to complete, the thread can work on another request.

Why ASP NET core is faster?

NET Core is faster for working with more modern libraries and programming languages. It is more lightweight and modular than . NET Framework, and you can use multiple versions of . NET in the same project.


2 Answers

Yes.

There is the property Response.IsClientConnected which is used to know if a long running process is still connected. The reason for this property is a processes will continue running even if the client becomes disconnected and must be manually detected via the property and manually shut down if a premature disconnect occurs. It is not by default to discontinue a running process on client disconnect.

Reference to this property: http://msdn.microsoft.com/en-us/library/system.web.httpresponse.isclientconnected.aspx

update

FYI this is a very bad property to rely on these days with sockets. I strongly encourage you to do an approach which allows you to quickly complete a request that notes in some database or queue of some long running task to complete, probably use RabbitMQ or something like that, that in turns uses socket.io or similar to update the web page or app once completed.

like image 197
King Friday Avatar answered Sep 19 '22 19:09

King Friday


How about don't do the async operation on an ASP.NET thread at all? Let the ASP.NET code call a service to queue the data search, then return to the browser with a token from the service, where it will then redirect to the result page that awaits the completed result? The result page will poll using the token from the service.

That way, you won't have to worry about whether or not ASP.NET will somehow learn that the browser has moved to a different page.

like image 26
John Saunders Avatar answered Sep 19 '22 19:09

John Saunders