IHttpContextAccessor Interface

Definition

Provides access to the current HttpContext, if one is available.

C#
public interface IHttpContextAccessor
Derived

Remarks

This interface should be used with caution. It relies on AsyncLocal<T> which can have a negative performance impact on async calls. It also creates a dependency on "ambient state" which can make testing more difficult.

Properties

HttpContext

Gets or sets the current HttpContext. Returns null if there is no active HttpContext.

Applies to

Product Versions
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0