diff --git a/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionDispatcher.cs b/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionDispatcher.cs index c80b66d2e5..20562c4c1e 100644 --- a/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionDispatcher.cs @@ -381,8 +381,6 @@ namespace Microsoft.AspNetCore.Http.Connections // Establish the connection var connection = _manager.CreateConnection(); - EnsureConnectionStateInternal(connection, options); - // Set the Connection ID on the logging scope so that logs from now on will have the // Connection ID metadata set. logScope.ConnectionId = connection.ConnectionId; @@ -604,6 +602,8 @@ namespace Microsoft.AspNetCore.Http.Connections return null; } + EnsureConnectionStateInternal(connection, options); + return connection; } @@ -630,7 +630,6 @@ namespace Microsoft.AspNetCore.Http.Connections if (StringValues.IsNullOrEmpty(connectionId)) { connection = _manager.CreateConnection(); - EnsureConnectionStateInternal(connection, options); } else if (!_manager.TryGetConnection(connectionId, out connection)) { @@ -640,6 +639,8 @@ namespace Microsoft.AspNetCore.Http.Connections return null; } + EnsureConnectionStateInternal(connection, options); + return connection; }