Check session availability or not.

I tried the code in Application_Error like this

 Session["mysession"] = "Some message"; 

but the problem is that the session is not available in Application_Error . So I want to check if the session is available or not.

+6
source share
1 answer

Session does not always exist in the context of the current Application_Error . Try the following:

 protected void Application_Error(object sender, EventArgs e) { if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState) { // Session exists Session["mysession"] = "Some message"; } } 
+15
source share

All Articles