To check if session is available or not
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 s开发者_开发知识库ession is available or not.
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";
}
}
精彩评论