c# - 在ASP.NET Core上检测与SSE的断开连接 - 编程笔记

时间:2020-05-20
本文章向大家介绍c# - 在ASP.NET Core上检测与SSE的断开连接 - 编程笔记,主要包括c# - 在ASP.NET Core上检测与SSE的断开连接 - 编程笔记使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

原文: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?

Answer

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;
} 

原文地址:https://www.cnblogs.com/lonelyxmas/p/12922971.html