From c10145f743694474489fc254a70ef8a0b73eb2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Thu, 26 Mar 2020 12:32:09 +0800 Subject: [PATCH] Use IConnectionEndPointFeature to get IMqttChannelAdapter.Endpoint in aspnetcore31 --- Source/MQTTnet.AspnetCore/MqttConnectionContext.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/MQTTnet.AspnetCore/MqttConnectionContext.cs b/Source/MQTTnet.AspnetCore/MqttConnectionContext.cs index 2aa9842..8f3f1be 100644 --- a/Source/MQTTnet.AspnetCore/MqttConnectionContext.cs +++ b/Source/MQTTnet.AspnetCore/MqttConnectionContext.cs @@ -25,7 +25,7 @@ namespace MQTTnet.AspNetCore _input = Connection.Transport.Input; _output = Connection.Transport.Output; } - + _reader = new SpanBasedMqttPacketBodyReader(); } @@ -37,6 +37,13 @@ namespace MQTTnet.AspNetCore { get { +#if NETCOREAPP3_1 + var endpointFeature = Connection.Features.Get(); + if (endpointFeature != null) + { + return endpointFeature.RemoteEndPoint.ToString(); + } +#endif var connection = Http?.HttpContext?.Connection; if (connection == null) {