English 中文(简体)
表达式会话: 确定会话还剩下多少时间而不调整到 最大值?
原标题:expressjs session: determine how much time left in session without resetting to original maxAge val?
I m dealing with an app that uses express-session in a node.js app. https://github.com/expressjs/session Session durations are being set with the maxAge property. According to the documentation for maxAge: Alternatively req.session.cookie.maxAge will return the time remaining in milliseconds, which we may also re-assign a new value to adjust the .expires property appropriately. The following are essentially equivalent var hour = 3600000 req.session.cookie.expires = new Date(Date.now() + hour) req.session.cookie.maxAge = hour For example when maxAge is set to 60000 (one minute), and 30 seconds has elapsed it will return 30000 until the current request has completed, at which time req.session.touch() is called to reset req.session.cookie.maxAge to its original value [emph added by me]. Essentially what I m wondering: is there is a way to know how long it is before a session will expire without simultaneously resetting the lifespan of the session? The end goal is to be able to give a prompt to the user just before the session expires. For example, you go on your banking site, and they ll give you a dialog saying your session is about to expire, with option to keep alive; if ignored, then you are re-directed to the logout page.
问题回答
I see this has been sitting out here for 5+ years unanswered, but I found this question searching for something else. Anyway, what is most likely happening is that you re using MemoryStore for your session. MemoryStore doesn t expire sessions, rather it s a "rolling" session wherein you are resetting the maxAge every time you ping/access the session. I battled with MemoryStore, but ultimately decided it was much easier to manage such things when you use Redis locally instead of MemoryStore. Further, you can check the expiration of the cookie with req.session.cookie.expires. Best way to do that is create a route that accesses the backend, where you can check the cookie expiration date




相关问题
why the session in iis automatically log out?

I used iis6, and when i called a function Directory.delete(), the all the session relate this website will be logged out. and i debugged the website, i found no exception. any one have ideas on this ? ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Can I get the size of a Session object in bytes in c#?

Is it possible to get the size(in bytes) of a Session object after storing something such as a datatable inside it? I want to get the size of a particular Session object, such as Session["table1"], ...

提供严格分类的出席会议物体

提供严格分类的与会机会的最佳方式是什么? 我正计划转而选择矩阵,这正在促使汇编者抱怨我的幻觉方案拟订方法......

PHP Session is not destroying after user logout

I m trying to create an authentication mechanism for my PHP Application and I m having difficulty destroying the session. I ve tried unsetting the authentication token which was previously set within ...

热门标签