简体   繁体   中英

Simulate ASP.NET TempData in nodejs

How can I create object like TempData in nodejs? I thought maybe I can set flag 'IsTempData' to session and at the end of an application I would clear sessions which have this flag selected. But there is a problem: I have many asynchronous functions where I use tempdata, so application may end before I use tempdata. I hope you understand what I mean by ending application:

connect()
.use(connect.bodyParser())
.use(connect.query())
.use(connect.favicon())
.use(connect.cookieParser())
.use(connect.session({ secret: 'your secret here' }))
.use(function (req, res) {
    somefunction();

    // end of application, here I will clear sessions which have tempdata flag selected
}).listen(1234);

I came across your post looking for the same behavior. Since I couldn't find anything, I decided to implement something of my own, which will hopefully help you as well: NodeJS TempData Provider

Keep in mind, this was put together rather quickly, so if you have any issues, I'd appreciate your feedback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM