'ASP.Net: How to stop page execution when browser disconnects?

If a browser requests an ASP.Net page and then the user clicks "stop" or navigates away, I thought that the browser would close the connection and ASP.Net would perhaps stop execution. I don't think that's the case since Dispose() is not called when I test this. Is there anyway to know when the browser/client has disconnected and then stop the page from executing?



Solution 1:[1]

You can check the IsClientConnected

    if (!Response.IsClientConnected){
        HttpContext.Current.Response.End();
        return;
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aristos