Detecting async client disconnect in ASP.NET MVC

后端 未结 4 932
悲哀的现实
悲哀的现实 2020-12-09 04:51

Given an async controller:

public class MyController : AsyncController 
{
    [NoAsyncTimeout]
    public void MyActionAsync() { ... }

    public void MyAct         


        
4条回答
  •  忘掉有多难
    2020-12-09 05:02

    It's just as @Darin says. HTTP is a stateless protocol which means that there are no way (by using HTTP) to detect if the client is still there or not. HTTP 1.0 closes the socket after each request, while HTTP/1.1 can keep it open for a while (a keep alive timeout can be set as a header). That a HTTP/1.1 client closes the socket (or the server for that matter) doesn't mean that the client has gone away, just that the socket hasn't been used for a while.

    There are something called COMET servers which are used to let client/server continue to "chat" over HTTP. Search for comet here at SO or on the net, there are several implementations available.

提交回复
热议问题