TokenCacheExtensions.AddDistributedTokenCache Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Aggiungere una cache dei token distribuiti.
public static Microsoft.Identity.Client.IConfidentialClientApplication AddDistributedTokenCache(this Microsoft.Identity.Client.IConfidentialClientApplication confidentialClientApp, Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> initializeDistributedCache);
static member AddDistributedTokenCache : Microsoft.Identity.Client.IConfidentialClientApplication * Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> -> Microsoft.Identity.Client.IConfidentialClientApplication
<Extension()>
Public Function AddDistributedTokenCache (confidentialClientApp As IConfidentialClientApplication, initializeDistributedCache As Action(Of IServiceCollection)) As IConfidentialClientApplication
Parametri
- confidentialClientApp
- IConfidentialClientApplication
Applicazione client riservata.
- initializeDistributedCache
- Action<IServiceCollection>
Azione che esegue e IServiceCollection tramite la quale si inizializza la cache distribuita.
Valori restituiti
Applicazione per il concatenamento.
Esempio
Il codice seguente aggiunge una cache dei token basata su REDIS e ne inizializza la configurazione.
app.AddDistributedTokenCache(services =>
{
// Redis token cache
// Requires to reference Microsoft.Extensions.Caching.StackExchangeRedis
services.AddStackExchangeRedisCache(options =>
{
options.Configuration = "localhost";
options.InstanceName = "Redis";
});
});
In alternativa, il codice seguente aggiunge una cache dei token basata su PostgreSQL e ne inizializza la configurazione.
app.AddDistributedTokenCache(services =>
{
// PostgreSQL token cache
// Requires to reference Microsoft.Extensions.Caching.Postgres
services.AddDistributedPostgresCache(options =>
{
options.ConnectionString = "Host=localhost;Database=mydb;Username=myuser;Password=mypassword";
options.SchemaName = "public";
options.TableName = "token_cache";
options.CreateIfNotExists = true;
});
});
Commenti
Non usare questo metodo in ASP.NET Core. È sufficiente aggiungere il metodo ConfigureServices.