maxswitcher maxswitcher - 1 year ago 126
C# Question

Access HttpContext.Current

I need to access current

in static method.

i just use
, how to do this in ASP.NET vNext?

Answer Source

HttpContext.Current doesn't exist anymore in ASP.NET 5, but there's a new IHttpContextAccessor that you can inject in your dependencies and use to retrieve the current HttpContext

public class MyComponent : IMyComponent {
    private readonly IHttpContextAccessor contextAccessor;

    public MyComponent(IHttpContextAccessor contextAccessor) {
        this.contextAccessor = contextAccessor;

    public string GetDataFromSession() {
        return contextAccessor.HttpContext.Session.GetString(*KEY*);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download