We are trying to scale up our application to run across multiple servers but are struggling to get this working.
Environment:
- Docker Containers - AWS Fargate
- AWS Application Load Balancers
- Redis
- Linux
- Kestral (not IIS)
The problem seems to be around sharing the session information - I looked into it (there isn't much documentation for this so I could be wrong) and it would seem that sessions are just dealt with in the Cookies rather then storing them in a Cache?
From what I can see the Cache encryption/decryption is based off MachineKey which in an environment like above - changes every time a deploy is made (invalidating everyones sessions by making the cookies unreadable) and is different on every instance of the container.
I am trying to work out how to store this MachineKey so every container can encrypt/decrypt the cookies it looks like this is possible by using redis to store this: Microsoft.AspNetCore.DataProtection.Redis
provides this ability but the Redis Setup is in Web.Core
and the Cookie stuff seems to be handled by Web.Mvc
(its the only thing that already has Microsoft.AspNetCore.DataProtection
as part of cookies but adding: services.AddDataProtection().PersistKeysToRedis();
requires a redis connection that only exists in Web.core
Has anyone been able to sort this on there applications? It seems fundamental to 1. not clearing out sessions every time an application is deployed 2. scaling without running one BIG Server without load balancing and redudancy.
1 Answer(s)
-
0
Hi,
We haven't tried such a scenario but you are right. All instances must use same MachineKey I guess. I have found a document for IIS (https://blogs.msdn.microsoft.com/vijaysk/2009/05/13/iis-7-tip-10-you-can-generate-machine-keys-from-the-iis-manager/) but couldn't find one for Kestrel.
I think you can find it on the web.