Session state is not available in this context

Viewed 42560

I want to read session id in application error event but always get error "Session state is not available in this context". Why? The strange thing is that I have the same code in another asp.net app and everything works fine.

void Application_Error(object sender, EventArgs e)
{

        var sessionId = Session.SessionID;
        //skipped code

}
4 Answers

You may get this error if you are using an Out-of-Process state mode for ASP.NET state server. You need to mark any classes you wish to save to session state with the [Serializable] attribute

Related