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,

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

protected void Session_Start(Object sender, EventArgs e)
{
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.