会话持续时间超过超时时间

时间:2020-01-16 18:12:15

标签: c# asp.net asp.net-mvc-4

为个人用户访问我的网站设置的会话似乎比web.config中指定的超时持续更长的时间,具体如下:

<system.web>
    <compilation targetFramework="4.5" debug="true"/>
    <httpRuntime targetFramework="4.5"/>
    <customErrors mode="Off"/>
    <trust level="Full"/>
    <machineKey decryption="AES" decryptionKey="shortened"/>
    <sessionState timeout="20"/>
</system.web>

我们还通过在Global.asax中使用以下方法,确保为每个用户的浏览会话固定会话ID:

protected void Session_Start(Object sender, EventArgs e)
{
    // Ensure we access the session so that it fixes the session ID for the
    // duration of the users browsing
    // SO.com/questions/2874078/asp-net-session-sessionid-changes-between-requests

    Session["init"] = 0;
}

但是我在日志中观察到,许多小时后返回的用户仍然使用相同的BrowserSessionIdentifier:

2020年1月16日,星期四02:44:45.840 AM 2729 1m52sjnc3b3uyzph1uhma54a Index_PageLoad

2020年1月16日,星期四05:09:57.253 2731 1m52sjnc3b3uyzph1uhma54a Index_PageLoad

(1m52sjnc3b3uyzph1uhma54a是从 this.HttpContext.Session.SessionID; 每次获取的值)

我已经看过几次了-但是不是我期望的那样(也不是我需要它如何工作)。

有什么想法吗?


更多详细信息-我还实现了会话超时属性,该属性已放置在处理上述内容的控制器上:

public class SessionTimeoutAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        if (HttpContext.Current.Session["init"] == null)
        {
            filterContext.Result = new RedirectResult("~/Timeout");
            return;
        }
        base.OnActionExecuting(filterContext);
    }
}

日志显示,这实际上从未触发过。会话以某种方式保持活跃,但我不知道如何或为什么。

0 个答案:

没有答案