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
  • 704,970
  • 168
  • 1,303
  • 1,425
MaxCoder88
  • 2,324
  • 5
  • 40
  • 57

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,838
  • 2
  • 39
  • 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,853
  • 3
  • 19
  • 34