-1

I have a mvc project.

problem 1 )

When i start my project in the my visual studio, session_end (in global.asax) starts. is that normal ? i dont open session and close session at the beginning of the project but it works.

problem 2)

The method i have written in my class works when session_end fires. i set it like this. but when i starts my project, session_end fires. anyway, this is not a big problem for me,,,,

BUT

my method has

if (HttpContext.Current.Session["id"] != null)

this line. when this line works, the error occurs

NULL REFERENCE EXCEPTION

An exception of type 'System.NullReferenceException' occurred in blabla.dll but was not handled in user code Additional information: Object reference not set to an instance of an object.


how can I fix this?

canmustu
  • 1,426
  • 2
  • 16
  • 28

1 Answers1

0

It's because your HttpContext or Current is null. if you using c#6 you can do this:

if (HttpContext?.Current?.Session["id"] != null)

or you can check for null separately.

SᴇM
  • 6,506
  • 3
  • 23
  • 36