TokenCacheExtensions.AddDistributedTokenCache 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
新增分散式代幣快取。
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
參數
- confidentialClientApp
- IConfidentialClientApplication
機密客戶申請。
- initializeDistributedCache
- Action<IServiceCollection>
採取行動 IServiceCollection ,透過 和 初始化分散式快取。
傳回
關於連鎖的應用。
範例
以下程式碼基於 REDIS 新增一個標記快取並初始化其設定。
app.AddDistributedTokenCache(services =>
{
// Redis token cache
// Requires to reference Microsoft.Extensions.Caching.StackExchangeRedis
services.AddStackExchangeRedisCache(options =>
{
options.Configuration = "localhost";
options.InstanceName = "Redis";
});
});
或者以下程式碼會基於 PostgreSQL 新增一個令牌快取並初始化其設定。
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;
});
});
備註
不要在 ASP.NET Core 中使用這個方法。 只要改用 ConfigureServices 方法就好。