HttpConnectionContextExtensions.GetHttpContext(ConnectionContext) Method

Definition

Gets the HttpContext associated with the connection, if there is one.

C#
public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext (this Microsoft.AspNetCore.Connections.ConnectionContext connection);
C#
public static Microsoft.AspNetCore.Http.HttpContext? GetHttpContext (this Microsoft.AspNetCore.Connections.ConnectionContext connection);

Parameters

connection
ConnectionContext

The ConnectionContext representing the connection.

Returns

The HttpContext associated with the connection, or null if the connection is not HTTP-based.

Remarks

SignalR connections can run on top of HTTP transports like WebSockets or Long Polling, or other non-HTTP transports. As a result, this method can sometimes return null depending on the configuration of your application.

Applies to

Produkt Versioner
ASP.NET Core 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0