如果访问SessionID,ASP.Net Inproc会话超时是否重置?

时间:2021-03-08 03:27:05

I read here that an inproc asp.net session resets it's timeout everytime it is accessed (read or write). My question is, if the timeout is also reset if I only read the sessionID?

我在这里读到,每次访问(读或写)时,inproc asp.net会话都会重置它的超时。我的问题是,如果我只读取sessionID,那么超时也会被重置?

Example: Session timeout is set to 20 min. After 15 min. of inactivity I load a page and read the Session.SessionID. Will the session still exist after 10 more min.?

示例:会话超时设置为20分钟。 15分钟后不活动我加载页面并读取Session.SessionID。 10分钟后会话是否仍然存在?

And one more question: Does it matter if the page is loaded directly or accesses via AJAX?

还有一个问题:如果直接加载页面或通过AJAX访问是否重要?

2 个解决方案

#1


It appears to me that you are mixing up two different things: Reading a value from Session state (in code) differs from attaching an instance of SessionState to the current Request.

在我看来,你混合了两个不同的东西:从Session状态(代码中)读取值不同于将SessionState的实例附加到当前Request。

Unless I am very much mistaken, the timeout is not refreshed whenever you access a Session object (again, in code), rather it is refreshed when a new request is served. This happens because the SessionState item is itself added to the Cache (and expiration policy is set)

除非我非常错误,否则无论何时访问Session对象(在代码中),都不会刷新超时,而是在提供新请求时刷新。发生这种情况是因为SessionState项本身已添加到Cache中(并设置了过期策略)

So, to answer your question: The timeout will not be reset.

所以,回答你的问题:超时不会被重置。

To elaborate on the example you gave: The timeout will be reset on the load of the page, rather than when you read the SessionID in code.

详细说明您给出的示例:超时将在页面加载时重置,而不是在代码中读取SessionID时。

#2


Accessing SessionID doesn't affect session timeout. If you take a peek with Reflector, the SessionID property (implemented in HttpSessionStateContainer) looks like this:

访问SessionID不会影响会话超时。如果你看一下Reflector,SessionID属性(在HttpSessionStateContainer中实现)如下所示:

public string SessionID
{
    get
    {
        if (this._id == null)
        {
            this._id = this._stateModule.DelayedGetSessionId();
        }
        return this._id;
    }
}

Which doesn't touch the underlying stored items.

哪个不触及底层存储的项目。

Also, at that level it doesn't matter where the request came from (ajax/normal).

此外,在该级别,请求来自何处(ajax / normal)并不重要。

#1


It appears to me that you are mixing up two different things: Reading a value from Session state (in code) differs from attaching an instance of SessionState to the current Request.

在我看来,你混合了两个不同的东西:从Session状态(代码中)读取值不同于将SessionState的实例附加到当前Request。

Unless I am very much mistaken, the timeout is not refreshed whenever you access a Session object (again, in code), rather it is refreshed when a new request is served. This happens because the SessionState item is itself added to the Cache (and expiration policy is set)

除非我非常错误,否则无论何时访问Session对象(在代码中),都不会刷新超时,而是在提供新请求时刷新。发生这种情况是因为SessionState项本身已添加到Cache中(并设置了过期策略)

So, to answer your question: The timeout will not be reset.

所以,回答你的问题:超时不会被重置。

To elaborate on the example you gave: The timeout will be reset on the load of the page, rather than when you read the SessionID in code.

详细说明您给出的示例:超时将在页面加载时重置,而不是在代码中读取SessionID时。

#2


Accessing SessionID doesn't affect session timeout. If you take a peek with Reflector, the SessionID property (implemented in HttpSessionStateContainer) looks like this:

访问SessionID不会影响会话超时。如果你看一下Reflector,SessionID属性(在HttpSessionStateContainer中实现)如下所示:

public string SessionID
{
    get
    {
        if (this._id == null)
        {
            this._id = this._stateModule.DelayedGetSessionId();
        }
        return this._id;
    }
}

Which doesn't touch the underlying stored items.

哪个不触及底层存储的项目。

Also, at that level it doesn't matter where the request came from (ajax/normal).

此外,在该级别,请求来自何处(ajax / normal)并不重要。