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

前端 未结 3 1082
我在风中等你
我在风中等你 2021-01-05 05:52

Environment:

  • Windows Server 2003 - IIS 6.x
  • ASP.NET 3.5 (C#)
  • IE 7,8,9
  • FF (whatever the latest 10 versions are)
相关标签:
3条回答
  • 2021-01-05 06:30

    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.

    0 讨论(0)
  • 2021-01-05 06:36

    Another option is to use Threading (System.Threading).
    When the user sends the search criteria, the server begins processing the page request, creates a new Thread responsible for executing the search, and finishes the response getting back to the browser and redirecting to the results page while the thread continues to execute on the server background.
    The results page would keep verifying on the server if the query execution had finished as the started Thread would share the progress information. When it does finish, the results are returned when the next ajax call is done by the results page.

    It could also be considered using WebSockets. In a sense that the Webserver itself could tell the browser when it is done processing the query execution as it offers full-duplex communications channels.

    0 讨论(0)
  • 2021-01-05 06:49

    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.

    0 讨论(0)
提交回复
热议问题