Search code examples
aspnetboilerplate

aspnetboilerplate session timeout & redis implementation


I am using ABP framework with MVC 5 and deployed into Azure. I have listed few session related questions below.

  1. I used HttpContext.Current.Session in WebMpa project and AbpSession in Application services, but unable to get the data from AbpSession using HttpContext.Current.Session in WebMpa project, both are saving data in different place?

  2. Am using static helper class and static property to Get/Set HttpContext.Current.Session value, if i want to remove the HttpContext.Current.Session any easiest way is available(with minimal code change), it could be better if we can get AbpSession from that static class?

  3. I want to alert users 20 secs prior to session expired, is there any build in option available in ABP?

  4. If I enable to Redis Cache implementation in my application, Cache, HttpContext.Current.Session, AbpSession and TempData will works without any issues and all should Get/Set values from Redis datasource?


Solution

    1. AbpSession is not extending HttpContext.Current.Session. So the answer is yes you cannot share data btw AbpSession and Session.
    2. Don't use static for injectable types. bad practise!
    3. There's no built-in function for that. You can achieve this with a javascript function. When you finish a request, start timer. You know the session timeout duration. So when it reaches to 20secs, show an alert window to continue session. If answer is Yes then make a new request to slide session.
    4. No! As i stated, Session and AbpSession is totally different things and you cannot share btw them.

    PS: AbpSession stores claims. And it's extendable. So you can store any item in AbpSession. See the link to understand how to extend AbpSession https://gist.github.com/hikalkan/67469e05475c2d18cb88