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

jaxmeier

All,

We have several ASP.NET websites that are using the RedisSessionStateProvider for session storage. We are just starting to spin up an instance of ServiceStack, and I would like to pass the sessionId from ASP.NET to ServiceStack, then use the stored values from Redis in ServiceStack sessions.

So far I have been able to pass the sessionID in the header, retrieve it in my plugin, and get the value matching that sessionId from Redis back as a string.

My problem is is a typed object going into Redis from ASP.NET, but I can't get it as the type object coming out in ServiceStack.

Any and all suggestions are appreciated.

Thanks, B

mythz

ServiceStack Sessions are completely decoupled/independent from ASP.NET Sessions and its Session Provider model. As they're 2 completely different technologies they're incompatible with each other, you'll need a separate "migration step" to extract out data from ASP.NET Session State, populate your Typed Custom UserSession and save it in ServiceStack.

ServiceStack Sessions are simply your Typed UserSession persisted in the registered Caching Provider at a key identified from the Cookie SessionId.

Navigating all User Sessions in Cache

The Inspecting Persisted User Sessions illustrates how User Sessions are serialized POCO's stored in the Registered ICacheClient at the following key:

urn:iauthsession:{SessionId}

Where {SessionId} is either the users ss-id or ss-pid cookie depending on whether the user was authenticated with RememberMe=true which instructs ServiceStack to save the session against the ss-pid permanent cookie - this preference is stored in the ss-opt=perm cookie.

Since they're just plain POCO's stored at a predictable key format, we can easily iterate through all user sessions by using the ICacheClient API's directly, e.g:

var sessionPattern = IdUtils.CreateUrn<IAuthSession>(""); //= urn:iauthsession:
var sessionKeys = Cache.GetKeysStartingWith(sessionPattern).ToList();

var allSessions = Cache.GetAll<IAuthSession>(sessionKeys);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ASP.NET vnext and ServiceStack.redis

From Dev

Storing session data in asp .net mvc

From Dev

Storing session data in asp .net mvc

From Dev

Reconnecting to Servicestack session in an asp.net MVC4 application

From Dev

Sliding Session Expiration with ServiceStack Authentication on ASP.NET MVC

From Dev

Sliding Session Expiration with ServiceStack Authentication on ASP.NET MVC

From Dev

Laravel not storing session data in Redis

From Dev

MVC4 and ServiceStack session in Redis

From Dev

MVC4 and ServiceStack session in Redis

From Dev

Save user session in Redis with ASP.NET Core in Azure

From Dev

Storing and Retrieving System.Data.Dataset to Redis with ServiceStack

From Dev

Storing user data in session store or retrieving from database in each request in asp.net core?

From Dev

Is it possible to share SQL Server database for storing session state in Asp.Net Web Forms

From Dev

Aspnet5 - ServiceStack.Redis - custom session provider

From Dev

Can't connect to Redis server using ASP.NET Session State Provider

From Dev

ASP.NET/ServiceStack Root URL at startup

From Dev

ServiceStack.Redis with F# is not storing data. But nearly the same code in C# works

From Dev

ServiceStack.Redis with F# is not storing data. But nearly the same code in C# works

From Dev

ASP.NET Storing Cross Request Data

From Dev

Storing a global object in ASP.NET MVC

From Dev

ASP.NET Storing Cross Request Data

From Dev

Storing image in database with asp.net mvc

From Dev

Reading barcode in asp.net

From Dev

session variables in an ASP.NET

From Dev

session not working asp.net

From Dev

Alternative to session in ASP.NET

From Dev

asp.net Login Session

From Dev

twemproxy (nutcracker) performance degradation with .net ServiceStack.Redis client

From Dev

Whether to use protobuf-net to serialize primitives before storing in Redis

Related Related

  1. 1

    ASP.NET vnext and ServiceStack.redis

  2. 2

    Storing session data in asp .net mvc

  3. 3

    Storing session data in asp .net mvc

  4. 4

    Reconnecting to Servicestack session in an asp.net MVC4 application

  5. 5

    Sliding Session Expiration with ServiceStack Authentication on ASP.NET MVC

  6. 6

    Sliding Session Expiration with ServiceStack Authentication on ASP.NET MVC

  7. 7

    Laravel not storing session data in Redis

  8. 8

    MVC4 and ServiceStack session in Redis

  9. 9

    MVC4 and ServiceStack session in Redis

  10. 10

    Save user session in Redis with ASP.NET Core in Azure

  11. 11

    Storing and Retrieving System.Data.Dataset to Redis with ServiceStack

  12. 12

    Storing user data in session store or retrieving from database in each request in asp.net core?

  13. 13

    Is it possible to share SQL Server database for storing session state in Asp.Net Web Forms

  14. 14

    Aspnet5 - ServiceStack.Redis - custom session provider

  15. 15

    Can't connect to Redis server using ASP.NET Session State Provider

  16. 16

    ASP.NET/ServiceStack Root URL at startup

  17. 17

    ServiceStack.Redis with F# is not storing data. But nearly the same code in C# works

  18. 18

    ServiceStack.Redis with F# is not storing data. But nearly the same code in C# works

  19. 19

    ASP.NET Storing Cross Request Data

  20. 20

    Storing a global object in ASP.NET MVC

  21. 21

    ASP.NET Storing Cross Request Data

  22. 22

    Storing image in database with asp.net mvc

  23. 23

    Reading barcode in asp.net

  24. 24

    session variables in an ASP.NET

  25. 25

    session not working asp.net

  26. 26

    Alternative to session in ASP.NET

  27. 27

    asp.net Login Session

  28. 28

    twemproxy (nutcracker) performance degradation with .net ServiceStack.Redis client

  29. 29

    Whether to use protobuf-net to serialize primitives before storing in Redis

HotTag

Archive