7

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>                
}
Community
  • 1
  • 1
Malik Kashmiri
  • 5,741
  • 11
  • 44
  • 80
  • 1
    take a look at this. [https://stackoverflow.com/questions/46877349/accessing-session-object-inside-an-asp-core-2-view](https://stackoverflow.com/questions/46877349/accessing-session-object-inside-an-asp-core-2-view) – Andhika Kurnia Aufa Azham Oct 23 '17 at 02:58
  • This https://stackoverflow.com/a/51939627/2238515 solved for me – Almeida May 08 '19 at 11:19

0 Answers0