ComponentSpace
SAML for ASP.NET CoreWeb Farm Guide

Copyright © ComponentSpace Pty Ltd 2017-2023. All rights reserved.
www.componentspace.com

ComponentSpace SAML for ASP.NET Core Web Farm Guide

ContentsIntroduction ............................................................................................................................................ 1
SSO Session Store.................................................................................................................................... 1
ID Cache .................................................................................................................................................. 1
Artifact Cache.......................................................................................................................................... 1
Redis Cache ............................................................................................................................................. 1
SQL Server Cache .................................................................................................................................... 2i

ComponentSpace SAML for ASP.NET Core Web Farm Guide

Introduction
This guide describes the steps required to support SAML SSO in a web farm deployment.

SSO Session StoreBoth identity providers and service providers use the SSO session store.
The default SSO session store stores data in an IDistributedCache.
The implementation of IDistributedCache may be specified through dependency injection.
The default implementation of IDistributedCache caches to memory.
This is suitable for web farm deployments where a load balancer and sticky sessions are used.
For web farm deployments where sticky sessions are not used, an IDistributedCache implementationsuch as the RedisCache or SqlServerCache should be specified.

ID CacheA service provider stores SAML assertion IDs in an ID cache to detect potential replay attacks. An
identity provider does not use the ID cache.
The default ID cache stores IDs in an IDistributedCache.
The implementation of IDistributedCache may be specified through dependency injection.
The default implementation of IDistributedCache caches to memory.
For web farm deployments, an IDistributedCache implementation such as the RedisCache orSqlServerCache should be specified.
If acting as an identity provider, the ID cache may be ignored.

Artifact Cache
Artifacts are stored in an artifact cache when SAML messages are transmitted using the HTTP
Artifact binding. Otherwise, the artifact cache is not used.
The default artifact cache stores artifacts in an IDistributedCache.
The implementation of IDistributedCache may be specified through dependency injection.
The default implementation of IDistributedCache caches to memory.
For web farm deployments, an IDistributedCache implementation such as the RedisCache orSqlServerCache should be specified.
If the HTTP artifact binding is not used, the artifact cache may be ignored.

Redis Cache
The following code configures a Redis cache that’s used for the SSO session store, ID cache andArtifact cache.
// Add SAML SSO services.

1

ComponentSpace SAML for ASP.NET Core Web Farm Guide

services.AddSaml();// Add the Redis cache.
services.AddDistributedRedisCache (option =>{option.Configuration = Configuration.GetConnectionString ("RedisConnection");});The following configuration specifies a Redis cache on localhost using the default port 6379.
"ConnectionStrings": {"RedisConnection": "localhost"},For information on Redis, refer to:https://redis.io/
For information on distributed caches, refer to:https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed
For information on Redis configuration strings, refer to:https://stackexchange.github.io/StackExchange.Redis/Configuration.html
A Windows port of Redis is available at:https://github.com/MicrosoftArchive/redis

SQL Server Cache
The following code configures a SQL server cache that’s used for the SSO session store, ID cache andArtifact cache.
// Add SAML SSO services.
services.AddSaml(Configuration.GetSection("SAML"));// Add the SQL server cache.
services.AddDistributedSqlServerCache(options =>{options.ConnectionString = Configuration.GetConnectionString("DistCache");options.SchemaName = "dbo";
options.TableName = "TestCache";});

The following configuration specifies the connection string for the cache database on(localdb)\MSSQLLOCALDB. In a production environment, SQL Server or another RDBMS should be
used.

2

ComponentSpace SAML for ASP.NET Core Web Farm Guide"ConnectionStrings": {"DistCache":"Server=(localdb)\\MSSQLLOCALDB;Database=DistCache;Trusted_Connection=True;MultipleActiv
eResultSets=true"},

The database may be created using various tools including the SQL Server Management Studio andVisual Studio’s SQL Server Object Explorer.
Once created, run the sql-cache tool to initialize the database.
dotnet sql-cache create "Data Source=(localdb)\MSSQLLocalDB;Initial
Catalog=DistCache;Integrated Security=True;" dbo TestCache

For information on distributed caches, refer to:https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed3