Session state is not available in this context in Global.asax

Amin Jariwala picture Amin Jariwala · Feb 16, 2016 · Viewed 11k times · Source

I am getting and error message when i'm trying to get Session value in Global.aspx:

enter image description here

I have tried another method to get Session value and result is same but message is different:

enter image description here

This error occur in Application_Error method and Session is not null but it shows that it is null. I have put this Session code in (HttpContext.Current.Session != null) condition so it is working fine but i want session value which is not getting with this method.

enter image description here

Please help me. Thanks

Answer

Sumit Jambhale picture Sumit Jambhale · Feb 16, 2016

Global.asax file is generally used to track the application level events and those are shareable between the different logged in users so it might not be possible to get the session value in global.asax events.

For error logging you can use the httpModule

Below link for error logging using httpModule

http://www.codeproject.com/Articles/16171/An-HTTP-Module-for-ASP-NET-Error-Handling

Below link is for getting session values in httpModule

Can I access session state from an HTTPModule?