原文:c# - 在ASP.NET Core上检测与SSE的断开连接 - 编程笔记
c# - 在ASP.NET Core上检测与SSE的断开连接
Detecting a disconnection from SSE on ASP.NET Core
I want to detect a disconnection from SSE (Server Send Events) on ASP.NET Core. Old way Response.IsClientConnected
not working. Do you have solution for this problem?
I found temporary solution to my question. Temporary because IsCancellationRequested
is detected when trying to send request and it failed, not when user disconnected before send request
if (HttpContext.RequestAborted.IsCancellationRequested == true)
{
break;
}
翻译
我想检测与ASP.NET Core上的SSE(服务器发送事件)断开连接。旧方法Response.IsClientConnected
不起作用。您有解决此问题的方法吗?
最佳答案
我找到了临时解决方案。临时,因为尝试发送请求时检测到IsCancellationRequested
且失败,而不是在发送请求之前用户断开连接时出现if (HttpContext.RequestAborted.IsCancellationRequested == true)
{
break;
}