问题
If a browser requests an ASP.Net page and then the user clicks "stop" or navigates away, I though 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?
回答1:
You can check the IsClientConnected
if (!Response.IsClientConnected){
HttpContext.Current.Response.End();
return;
}
来源:https://stackoverflow.com/questions/5670377/asp-net-how-to-stop-page-execution-when-browser-disconnects