適用於 Azure 受管理快取服務的 ASP.NET 工作階段狀態提供者組態設定
重要
Microsoft 建議所有新的開發都使用 Azure Redis 快取。 如需選擇 Azure 快取供應專案的目前檔和指引,請參閱 哪個 Azure 快取供應專案適合我?
本主題涵蓋適用于 ASP.NET 之 Azure 受控快取服務 會話狀態提供者的組態設定。 這些設定是在 web.config 檔案中sessionState元素的providers區段中指定。
工作階段狀態組態設定
屬性 | 描述 |
---|---|
需要名稱 () |
sessionState元素用來參考提供者的提供者「易記」名稱。 |
類型 (必要) |
提供者的 .NET Framework 型別字串。 必要值請參閱下面的附註。 |
cacheName (必要) |
Azure 快取的名稱。 這必須設定為 |
dataCacheClientName (選擇性) |
要從 dataCacheClients 組態區段使用的 dataCacheClient 區 段名稱。 只有在web.config檔案中指定多個 dataCacheClient 區段時,才需要這個屬性。 根據預設,提供者將使用名為 |
applicationName (選擇性) |
在建立用於儲存輸出快取資料的快取金鑰時,提供者所使用的字串值。 預設為空字串。 未設定此屬性時,提供者會使用 HttpRuntime.AppDomainAppId 的值做為其內部使用的快取索引鍵的一部分。 與工作階段狀態功能不同,您不會想要在不同 ASP.NET 應用程式間共用輸出快取資料 (例如,/contoso 和 /AdventureWorks 無法共用輸出快取資料)。 取而代之的是確保相同應用程式的不同實體例項全都可以存取相同的輸出快取資料。 有兩種不統方式可以完成此動作:
|
useBlobMode (選擇性) |
布林值,指定是否要以單一序列化項目的形式載入及儲存工作階段狀態資料。 在這個版本中,此屬性必須設定為 |
nonInlinedAdditionalLifetime (不支援的) |
在這個版本中,不支援此屬性。 |
retryInterval (選擇性) |
一段時間,在與快取通訊時若發生錯誤,每次重試之間要等候的時間長度。 此值所使用的字串格式為 |
retryCount (選擇性) |
整數值,讓提供者知道要在快取通訊發生錯誤時重試幾次。 請注意,並非所有操作都可重試。 預設值為重試三次。 提供者會在每次重試嘗試之間睡眠已設定 的 retryInterval 時間。 |
inlinedKeys (不支援的) |
在這個版本中,不支援此屬性。 |
maxInlinedStringLength (不支援的) |
在這個版本中,不支援此屬性。 |
注意
類型屬性應設定為 “Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache”
。
範例
<!-- Non-cache sections omitted for space -->
<configuration>
<configSections>
<section name="dataCacheClients"
type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core"
allowLocation="true"
allowDefinition="Everywhere" />
<section name="cacheDiagnostics"
type="Microsoft.ApplicationServer.Caching.AzureCommon.DiagnosticsConfigurationSection, Microsoft.ApplicationServer.Caching.AzureCommon"
allowLocation="true"
allowDefinition="Everywhere" />
</configSections>
<system.web>
<!-- Azure Caching session state provider -->
<sessionState mode="Custom" customProvider="AFCacheSessionStateProvider">
<providers>
<add name="AFCacheSessionStateProvider"
type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"
cacheName="default"
dataCacheClientName="default"
applicationName="AFCacheSessionState"/>
</providers>
</sessionState>
</system.web>
<dataCacheClients>
<dataCacheClient name="default">
<!--To use the in-role flavor of Azure Caching, set identifier to be the cache cluster role name -->
<!--To use the Azure Caching Service, set identifier to be the endpoint of the cache cluster -->
<autoDiscover
isEnabled="true"
identifier="[Cache role name or Service Endpoint]" />
<!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />-->
<!--Use this section to specify security settings for connecting to your cache.
This section is not required if your cache is hosted on a role that is a part
of your cloud service. -->
<!--<securityProperties mode="Message" sslEnabled="false">
<messageSecurity authorizationInfo="[Authentication Key]" />
</securityProperties>-->
</dataCacheClient>
<cacheDiagnostics>
<crashDump dumpLevel="Off" dumpStorageQuotaInMB="100" />
</cacheDiagnostics>
</dataCacheClients>
</configuration>
注意
僅有快取 NuGet 封裝會新增 cacheDiagnostics
區段到 ASP.NET Web 角色用戶端。 如需詳細資訊,請參閱關於 Azure 受控快取服務的 ClientDiagnosticLevel。