您的位置:首页 > 移动开发

配置ASP.NET网站使用AppFabric Caching存储Session数据

2010-08-10 16:01 651 查看
网上很多这类配置资料都是CTP版本的,正式版本中已经不能这样用了。

首先确保需要放到Session中的对象是支持二进制序列化的对象,

修改web.config文件如下:

<configSections>
<section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere" />

</configSections>

<!-- 分布式缓存配置项 -->
<dataCacheClient>
<hosts>
<host name="sr-af-01" cachePort="22233" />
</hosts>

<!-- 不使用任何安全策略,

默认情况下安装好AppFabric后,

还需要配置有权限访问缓存的帐号,

此处配置为允许任何帐号连接缓存服务器,

注意需要AppFabric服务器也配置为不需要授权(修改ClusterConfig.xml)。 -->
<securityProperties mode="None" protectionLevel="None" />

</dataCacheClient>

<sessionState mode="Custom" cookieName=".XXXXSessionId" customProvider="AppFabricCacheSessionStoreProvider">
<providers>
<!-- 为自定义会话状态指定命名缓存 -->
<add name="AppFabricCacheSessionStoreProvider"
type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider"
cacheName="XXXXSessionStore"

<!-- 如果有多个网站,需要用sharedId隔离各自的会话状态。-->
sharedId="XXXXSession" />
</providers>
</sessionState>

另附ClusterConfig.xml内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dataCache" type="Microsoft.ApplicationServer.Caching.DataCacheSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<dataCache size="Small">
<caches>
<cache consistency="StrongConsistency" name="default">
<policy>
<eviction type="Lru" />
<expiration defaultTTL="10" isExpirable="true" />
</policy>
</cache>
<cache consistency="StrongConsistency" name="XXXXSessionStore">
<policy>
<eviction type="Lru" />
<expiration defaultTTL="10" isExpirable="true" />
</policy>
</cache>
</caches>
<hosts>
<host replicationPort="22236" arbitrationPort="22235" clusterPort="22234"
hostId="1178671922" size="2047" leadHost="true" account="XXXX/sr-af-01$"
cacheHostName="AppFabricCachingService" name="sr-af-01" cachePort="22233" />
</hosts>
<advancedProperties>
<securityProperties mode="None" protectionLevel="None" />
</advancedProperties>
</dataCache>
</configuration>

PS:XXXX是屏蔽我们公司的名称。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐