开发者

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";
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜