0

I'm using below code within MVC controller class. My question is: when I attempt to run the code, I get the following error.

NullReferenceException

Code:

if (Session["User"] != null)
{
     return true;
} 

What am I wrong? What is the problem misunderstood related with session?

Cheers,

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MaxCoder88
  • 2,374
  • 6
  • 41
  • 59

2 Answers2

1

Session is null, presumably because you don't have a session state provider configured or because it's not available at the point that you're making the call (such as in the constructor).

Try This question

Community
  • 1
  • 1
Steve Morgan
  • 12,978
  • 2
  • 40
  • 49
1

Well, try first init session in global.asax. Just add this code to global.asax

protected void Session_Start(Object sender, EventArgs e)
{
}
Mennion
  • 2,873
  • 3
  • 20
  • 34