SessionTokenCacheProviderExtension.AddSessionPerUserTokenCache Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds an HTTP session-based per-user token cache to the service collection.
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSessionPerUserTokenCache (this Microsoft.Extensions.DependencyInjection.IServiceCollection services);
static member AddSessionPerUserTokenCache : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddSessionPerUserTokenCache (services As IServiceCollection) As IServiceCollection
Parameters
- services
- IServiceCollection
The services collection to add to.
Returns
The service collection.
Remarks
For this session cache to work effectively the ASP.NET Core session has to be configured properly. The latest guidance is provided at https://learn.microsoft.com/aspnet/core/fundamentals/app-state.
In the method public void ConfigureServices(IServiceCollection services)
in Startup.cs, add the following:
services.AddSession(option =>
{
option.Cookie.IsEssential = true;
});
In the method public void Configure(IApplicationBuilder app, IHostingEnvironment env)
in Startup.cs, add the following:
app.UseSession(); // Before UseMvc()
Because session token caches are added with scoped lifetime, they should not be used when TokenAcquisition
is also used as a singleton (for example, when using Microsoft Graph SDK).