We are have umbraco (v13.5.1) in loadbalanced environemnt. We encountered problems with user authentication. We run Umbraco on 3 pods in AWS kubernetes. While refreshing the page after login, we can see that user is randomly signed in and not. This clearly shows that load balancer is sending requst to random pods. We can't use sticky sessions on load balancer (nor cookie nor ip_hash), but would instead like to emply Sessions for that. However we are having trouble setting that. We have SQL cache set up, added the code to startup that is advised by .net and umbraco docs, but it seems to not work.
Is there any example what needs to be done for user sessions to be shared between servers?
Our Cache composer:
public class DistributedCacheComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
if (ServerInfo.Role == ServerRole.SchedulingPublisher)
{
builder.AddNotificationHandler<UmbracoApplicationStartingNotification, RunAddCacheTableMigration>();
}
builder.Services.AddDistributedSqlServerCache(options =>
{
options.SchemaName = "dbo";
options.TableName = nameof(CacheStore);
options.ConnectionString = builder.Config.GetConnectionString("umbracoDbDSN");
});
}
}
Startup:
public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
options.Cookie.Name = "custom_session_cookie";
});
....
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSession();
.....
}
Is ther something special we need to do on user login action, or do we need a special middleware?
Help would really be apriciated ❤️