Events
Power BI DataViz World Championships
Feb 14, 4 PM - Mar 31, 4 PM
With 4 chances to enter, you could win a conference package and make it to the LIVE Grand Finale in Las Vegas
Learn moreThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
IHttpContextAccessor
/HttpContext
in ASP.NET Core SignalRNote
This isn't the latest version of this article. For the current release, see the .NET 9 version of this article.
Important
This information relates to a pre-release product that may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
For the current release, see the .NET 9 version of this article.
IHttpContextAccessor/HttpContext generally should be avoided with SignalR because a valid HttpContext isn't always available. In most cases, the context doesn't exist (null
).
Even when an HttpContext instance is available, the context is dependent on the transport:
When working within a SignalR hub, you can access the HttpContext directly using the GetHttpContextExtensions.GetHttpContext method. This method returns the HttpContext for the current connection or null
if the connection isn't associated with an HTTP request. This is particularly useful for retrieving HTTP connection information, such as headers and query strings, directly within the hub. We recommend calling this method over IHttpContextAccessor for accessing HttpContext in the hub. For more information, see Use hubs in ASP.NET Core SignalR.
For guidance on IHttpContextAccessor/HttpContext in ASP.NET Core Blazor apps, see IHttpContextAccessor/HttpContext in ASP.NET Core Blazor apps.
ASP.NET Core feedback
ASP.NET Core is an open source project. Select a link to provide feedback:
Events
Power BI DataViz World Championships
Feb 14, 4 PM - Mar 31, 4 PM
With 4 chances to enter, you could win a conference package and make it to the LIVE Grand Finale in Las Vegas
Learn moreTraining
Module
Replace client-side polling with ASP.NET Core SignalR - Training
In this module, you use ASP.NET Core SignalR to replace client-side polling functionality in an existing web app.