Sliding Session Expiration with ServiceStack Authentication on ASP.NET MVC

robertmiles3

When using ServiceStack authentication with ASP.NET MVC, I wanted to implement a sliding session expiration. After some help from @mythz, I got it working. For any who want to do the same, see my answer for my final implementation.

robertmiles3

Here's my final implementation for a sliding session when using ServiceStack authentication in ASP.NET MVC...

public class SlideSessionExpirationAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var ssController = filterContext.Controller as ServiceStackController;
        if (ssController == null) return;

        // Get session and re-save to slide/update the expiration date
        var session = ssController.ServiceStackRequest.GetSession();
        if(session != null && session.IsAuthenticated)
            ssController.ServiceStackRequest.SaveSession(session, AppHost.SessionExpiration);

        base.OnActionExecuting(filterContext);
    }
}

...where AppHost.SessionExpiration is a static readonly TimeSpan that I declared in AppHost.cs. To use it, you can slap the attribute on a controller or method via [SlideSessionExpiration] or you can add it in via a global filter (like I did) inside FilterConfig.cs via...

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    /* ... other filters ... */
    filters.Add(new SlideSessionExpirationAttribute());
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Sliding Session Expiration with ServiceStack Authentication on ASP.NET MVC

From Dev

ASP.NET MVC Session Timeouts, Absolute or Sliding?

From Dev

Authentication with ASP.NET MVC site and ServiceStack API

From Dev

Reconnecting to Servicestack session in an asp.net MVC4 application

From Dev

ASP .NET Core Cookie Authentication expiration changes from timestamp to "Session" upon return

From Dev

asp net web api Authentication token expiration?

From Dev

Session without authentication with MemoryCacheClient in servicestack with MVC4

From Dev

How to handle SPA authentication to an ASP.NET MVC 5 back end without using Session?

From Dev

session timeout asp.net and authentication

From Dev

Storing an ASP.NET Session in Redis and reading it in ServiceStack

From Dev

How do I set the sliding expiration for a cookie that isn't managed by ASP.NET?

From Dev

How do I set the sliding expiration for a cookie that isn't managed by ASP.NET?

From Dev

ASP.NET Core MVC: setting expiration of identity cookie

From Dev

ASP.NET Core 1.0 - MVC 6 - Cookie Expiration

From Dev

authentication and authorizing in ASP.NET MVC 5

From Dev

Basic authentication in ASP.NET MVC 5

From Dev

asp.net MVC authentication with Shibboleth

From Dev

Identity cookie authentication in ASP.NET MVC

From Dev

ASP.NET MVC 4 User Authentication

From Dev

ASP.NET MVC not work with Forms Authentication

From Dev

Custom ASP.NET MVC Forms Authentication

From Dev

ASP .NET 4.7 MVC Authentication and Authorization Identity

From Dev

ASP.NET MVC Session State Timeout

From Dev

ASP.NET MVC 4 Session timeout

From Dev

Storing session data in asp .net mvc

From Dev

Authorization with Session variables in asp net mvc 5

From Dev

Storing session data in asp .net mvc

From Dev

ASP.NET MVC maintain object Session

From Dev

ASP.NET MVC Session Variables Lost

Related Related

  1. 1

    Sliding Session Expiration with ServiceStack Authentication on ASP.NET MVC

  2. 2

    ASP.NET MVC Session Timeouts, Absolute or Sliding?

  3. 3

    Authentication with ASP.NET MVC site and ServiceStack API

  4. 4

    Reconnecting to Servicestack session in an asp.net MVC4 application

  5. 5

    ASP .NET Core Cookie Authentication expiration changes from timestamp to "Session" upon return

  6. 6

    asp net web api Authentication token expiration?

  7. 7

    Session without authentication with MemoryCacheClient in servicestack with MVC4

  8. 8

    How to handle SPA authentication to an ASP.NET MVC 5 back end without using Session?

  9. 9

    session timeout asp.net and authentication

  10. 10

    Storing an ASP.NET Session in Redis and reading it in ServiceStack

  11. 11

    How do I set the sliding expiration for a cookie that isn't managed by ASP.NET?

  12. 12

    How do I set the sliding expiration for a cookie that isn't managed by ASP.NET?

  13. 13

    ASP.NET Core MVC: setting expiration of identity cookie

  14. 14

    ASP.NET Core 1.0 - MVC 6 - Cookie Expiration

  15. 15

    authentication and authorizing in ASP.NET MVC 5

  16. 16

    Basic authentication in ASP.NET MVC 5

  17. 17

    asp.net MVC authentication with Shibboleth

  18. 18

    Identity cookie authentication in ASP.NET MVC

  19. 19

    ASP.NET MVC 4 User Authentication

  20. 20

    ASP.NET MVC not work with Forms Authentication

  21. 21

    Custom ASP.NET MVC Forms Authentication

  22. 22

    ASP .NET 4.7 MVC Authentication and Authorization Identity

  23. 23

    ASP.NET MVC Session State Timeout

  24. 24

    ASP.NET MVC 4 Session timeout

  25. 25

    Storing session data in asp .net mvc

  26. 26

    Authorization with Session variables in asp net mvc 5

  27. 27

    Storing session data in asp .net mvc

  28. 28

    ASP.NET MVC maintain object Session

  29. 29

    ASP.NET MVC Session Variables Lost

HotTag

Archive