【问题标题】:SessionState Expires before timeoutSessionState 在超时前过期
【发布时间】:2014-03-20 20:01:20
【问题描述】:

我的网络应用程序中有 2 个会话
这是我如何声明我的会话:
全球.asax

protected void Session_Start(object sender, EventArgs e)
    {
        Session["login"] = "";
        Session["loginName"] = "Login";

    }

Web.config

<sessionState mode="InProc" cookieless="true" timeout="3600" /> <!--set the session timeout in minutes -->

会话类:

    public class clsSession
{
    //declare sessions
    private static object cardCode;
    private static object cardName;       

    //get/set Login id session
    public static string LoginIdSession
    {
        get
        {
            cardCode = HttpContext.Current.Session["login"];
            return cardCode == null ? "" : (string)cardCode;
        }
        set
        {
            HttpContext.Current.Session["login"] = value; 
        }
    }

    public static string LoginNameSession
    {
        get
        {
            cardName = HttpContext.Current.Session["loginName"];
            return cardName == null ? "Login" : (string)cardName; 
        }
        set
        {
            HttpContext.Current.Session["loginName"] = value;                 
        }
    }
}

问题是 2 个会话在超时前过期!

谢谢

【问题讨论】:

  • “这 2 个会话在超时前过期” - 你怎么知道?

标签: asp.net session c#-4.0


【解决方案1】:

这可能有很多原因。其中一些是:

  • 修改Machine.ConfigWeb.ConfigGlobal.asax
  • bin 目录或其内容被修改
  • 修改了虚拟目录的物理路径
  • IIS 中的设置很少会导致应用程序池或工作进程被回收。
  • 如果您设置了网络农场,则需要使用Out-Proc 会话状态(StateServer 或 SQL Server)

同时检查 IIS:

右击application pool -> properties

Recycling Tab -> "Recycle worker process (in minutes)" 如果选中此选项,请确保此处设置的时间应与web.config 中设置的会话超时时间相同。

Performance Tab -> “在适合之后关闭工作进程”确保此处设置的时间应该与web.config中设置的会话超时时间相同

【讨论】:

  • 感谢您的回答,我正在使用 Windows Server 并且还没有 IIS 角色。第二件事,我为什么要改变模式?你认为“InPorc”不是一个好习惯吗?
  • 我说“如果你有网络农场设置,你需要使用 Out-Proc”。
  • InProc 表示会话存储在工作进程的内存空间中,每次工作进程回收所有会话都会丢失。
猜你喜欢
  • 2013-08-22
  • 2011-04-13
  • 2018-12-14
  • 2011-09-09
  • 1970-01-01
  • 2015-09-15
  • 2023-03-05
  • 2011-06-24
相关资源
最近更新 更多