简体   繁体   中英

Clear specific controller session in ASP.NET MVC

In my project I'm using session to maintain some complex type data. I want to clear that session if that specified controller has not been hit for a specified amount of time , need to clear that specific session only that have been used in that controller not all the entire user session .

Let say,

BusinessController has some ActionMethods like Test1, Test2 .

The ActionMethod Test1 has some Session like Session["MyData"], Session["ListOfBusiness"] . The ActionMethod Test2 has some Session like Session["MyDataNew"], Session["ListOfBusiness"] .

I need to clear the session Session["MyData"], Session["ListOfBusiness"] only if BusinessController has not been hit for some time .

Thanks,

Guna

You can user ActionFilterAttribute. This will be called for every action so you can check in it whether controller has been hit or not.And for checking you can create a session in whcih you can store time when that controller hits or you can store time in database.

Whenever your BusinessController gets hit store time in session or database and when ActionFilterAttribute is execites get the time when BusinessController was las hit. I hope i have explained clearly.

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