tags:

views:

35

answers:

1

I tried some code in Application_Error like this

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

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

+1  A: 

Session doesn't always exist within 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";
    }
}
GenericTypeTea
This will give the exception "Session state is not available in this context." if session is not available.
Nadeem
Really...? Have you tried it?
GenericTypeTea
Yes I did. Now I doubt this may have something to do with Application_Error
Nadeem
@Nadeem - I updated my answer. That should solve the issue.
GenericTypeTea
Yeah this will do for me. Thanks !
Nadeem