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

試著忘記壹切 提交于 2019-12-11 11:02:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!