【问题标题】:To handle Session expires exception处理 Session expires 异常
【发布时间】:2010-11-16 06:31:58
【问题描述】:

我在我的应用程序中始终使用Session 变量,我的超时时间为 1 小时。在这里,我需要在我的应用程序中以任何全局方式捕获会话过期的异常。任何人都可以为此提供帮助。 提前谢谢...

【问题讨论】:

    标签: c# asp.net session-timeout


    【解决方案1】:

    在页面加载的顶部,您可以查看会话过期时间。

    if(Session["SomeValue"] == null)
       Response.Redirect("Login.aspx");//Session Expired.
    

    或者,您可以重定向到一个处理程序,该处理程序会在发现会话到期时执行您所需的操作。

    【讨论】:

      【解决方案2】:

      在页面的page_load事件或母版页中编写以下代码,

      if (Session["key"] == null)
          {
              Response.Redirect("Login_Page_Name");
          }
      

      【讨论】:

        【解决方案3】:

        您可以在 global.asax 文件中的 session_end 事件中处理此问题。还要确保在使用 sesison 变量之前检查过

        if (Session["YourKey"]!=null) { //做一点事 }

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多