遗留(经典)ASP代码会话问题

时间:2022-05-17 05:15:23

My question is about classic ASP, not ASP.Net. I ask expert here since search engine always tell me ASP.Net answers. My confusions are,

我的问题是关于经典的ASP,而不是ASP.Net。我问专家,因为搜索引擎总是告诉我ASP.Net的答案。我的困惑是,

  1. How to set session expiration time in classic ASP code or through configuration?
  2. 如何在经典ASP代码中或通过配置设置会话到期时间?

  3. How to extend session expire time? Is there a session expire event?
  4. 如何延长会话到期时间?是否有会话到期事件?

  5. How to know when session will expire?
  6. 如何知道会话何时到期?

thanks in advance, George

乔治,提前谢谢

5 个解决方案

#1


Please read this, I think it answers all your questions:

请阅读本文,我认为它可以回答您的所有问题:

http://www.w3schools.com/ASP/asp_sessions.asp

George,

There is a session_end event on the server side, but I suppose what you want is to detect it on client side.

服务器端有一个session_end事件,但我想你想要的是在客户端检测它。

To do that, you must set a timer on javascript, to end for example one minute before the session timeout and popup an alert. The alert gives the user the choice to extend the session. If the user says yes, then you make a post of the form (or an ajax call or anything that generates a request on the server side and so extends the session).

要做到这一点,你必须在javascript上设置一个计时器,例如在会话超时前一分钟结束并弹出警报。警报使用户可以选择扩展会话。如果用户说“是”,那么您将发布表单(或者ajax调用或在服务器端生成请求的任何内容,从而扩展会话)。

#2


George, ASP Classic sessions timeouts were finicky at best. I wouldn't rely on them. If you need to have more control over sessions I suggest you implement your own session management.

乔治,ASP经典会话超时充其量只是挑剔。我不会依赖它们。如果您需要更多地控制会话,我建议您实施自己的会话管理。

#3


Session.Timeout = 5 'five minutes

Session.Timeout = 5'五分钟

The session will expire after the number of minutes you've specified with no activity. For instance, if you set a session variable, and the user doesn't do anything (like refresh) for 5 minutes, then the session will be abandoned by the server.

会话将在您指定的没有活动的分钟数后过期。例如,如果您设置会话变量,并且用户没有做任何事情(如刷新)5分钟,那么服务器将放弃该会话。

Or, you can abandon it yourself using Session.Abandon

或者,您可以使用Session.Abandon自己放弃它

#4


Dont think you can find out when the session is going to expire bcos if say for ex. if the session timeout is 20 mins and the user is inactive for a period of say 19 mins and only 1 min is left and he/she clicks on the app, the session is valid for 20 mins more since it was activated.

不要认为你可以找到什么时候会议将到期bcos如果说为前。如果会话超时为20分钟且用户处于非活动状态的时间为19分钟且仅剩1分钟并且他/她点击应用程序,则会话自激活以来有效20分钟。

#5


Store the session cookie in your database instead of relying on the default classic asp session storage. Once stored in the database, you can keep it valid for as long as you like.

将会话cookie存储在数据库中,而不是依赖于默认的经典asp会话存储。一旦存储在数据库中,您可以根据需要保持有效。

In my opinion, it's too easy to lose your session with ASP classic.

在我看来,使用ASP classic失去你的会话太容易了。

#1


Please read this, I think it answers all your questions:

请阅读本文,我认为它可以回答您的所有问题:

http://www.w3schools.com/ASP/asp_sessions.asp

George,

There is a session_end event on the server side, but I suppose what you want is to detect it on client side.

服务器端有一个session_end事件,但我想你想要的是在客户端检测它。

To do that, you must set a timer on javascript, to end for example one minute before the session timeout and popup an alert. The alert gives the user the choice to extend the session. If the user says yes, then you make a post of the form (or an ajax call or anything that generates a request on the server side and so extends the session).

要做到这一点,你必须在javascript上设置一个计时器,例如在会话超时前一分钟结束并弹出警报。警报使用户可以选择扩展会话。如果用户说“是”,那么您将发布表单(或者ajax调用或在服务器端生成请求的任何内容,从而扩展会话)。

#2


George, ASP Classic sessions timeouts were finicky at best. I wouldn't rely on them. If you need to have more control over sessions I suggest you implement your own session management.

乔治,ASP经典会话超时充其量只是挑剔。我不会依赖它们。如果您需要更多地控制会话,我建议您实施自己的会话管理。

#3


Session.Timeout = 5 'five minutes

Session.Timeout = 5'五分钟

The session will expire after the number of minutes you've specified with no activity. For instance, if you set a session variable, and the user doesn't do anything (like refresh) for 5 minutes, then the session will be abandoned by the server.

会话将在您指定的没有活动的分钟数后过期。例如,如果您设置会话变量,并且用户没有做任何事情(如刷新)5分钟,那么服务器将放弃该会话。

Or, you can abandon it yourself using Session.Abandon

或者,您可以使用Session.Abandon自己放弃它

#4


Dont think you can find out when the session is going to expire bcos if say for ex. if the session timeout is 20 mins and the user is inactive for a period of say 19 mins and only 1 min is left and he/she clicks on the app, the session is valid for 20 mins more since it was activated.

不要认为你可以找到什么时候会议将到期bcos如果说为前。如果会话超时为20分钟且用户处于非活动状态的时间为19分钟且仅剩1分钟并且他/她点击应用程序,则会话自激活以来有效20分钟。

#5


Store the session cookie in your database instead of relying on the default classic asp session storage. Once stored in the database, you can keep it valid for as long as you like.

将会话cookie存储在数据库中,而不是依赖于默认的经典asp会话存储。一旦存储在数据库中,您可以根据需要保持有效。

In my opinion, it's too easy to lose your session with ASP classic.

在我看来,使用ASP classic失去你的会话太容易了。