Skip to content

[SignalR] How Hubs interact with HttpContext #13508

@analogrelay

Description

@analogrelay

We should have a document describing the complex interations between Hubs and HttpContext.

  • In a Hub you can get an HttpContext via Context.GetHttpContext() extension method, but it's not guaranteed to work
  • Long Polling uses a "simulated" context
  • There's no context at all when using Azure SignalR
  • IHttpContextAccessor should be avoided
  • SignalR has some support for non-HTTP transports (nothing officially supported yet but some future ideas) and those wouldn't even have an HttpContext so it's considered a good design practice to avoid using HttpContext at all in Hubs (to allow portability to non-HTTP transports)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions