Asp.net Core An object reference is required for the non-static field, method, or property 'HttpContext.Session

Viewed 6816

Problem

I am setting session in login controller after successfully login when I redirect it to application Home Index page to show username at nav bar I am getting session butt it gives me this error

An object reference is required for the non-static field, method, or property 'HttpContext.Session

Code in index.cshtml

@if (@HttpContext.Session.GetString("Name") != null)
{
    <a href="/Account/Sigout" class="btn btn-outline-primary d-block">@HttpContext.Session.GetString("Name")</a>                
}
0 Answers
Related