配置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是屏蔽我们公司的名称。
首先确保需要放到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是屏蔽我们公司的名称。
相关文章推荐
- (WebSite----Asp.Net Configuration----->无法连接到SQL Server数据库------>选择数据存储区---->应用程序当前被配置为使用提供程序:AspNetSqlProvider)解决方案
- 用Appfabric cache存储asp.net Session遇到的问题及总结(转)
- 用Appfabric cache存储asp.net Session遇到的问题及总结
- (WebSite----Asp.Net Configuration----->无法连接到SQL Server数据库------>选择数据存储区---->应用程序当前被配置为使用提供程序:AspNetSqlProvider)解决方案
- IIS部署ASP.NET网站后提示只有在配置文件或 Page 指令中将 enableSessionState 设置为 true 时,才能使用会话状态...
- 未能将网站 xxx配置为使用 ASP.NET 4.0。为了使此网站正确运行,您必须将它手动配置为使用 ASP.NET 4.0
- ASP.NET 网站管理—数据存储问题
- asp.net SessionState模式的配置及使用
- Asp.net Core中使用Redis 来保存Session, 读取配置文件
- 进入 ASP.NET 世界 - 第 2 部分:使用 SQL Server 2000 创建数据存储层
- 未安装SQL Server Express的情况下使用Asp.Net的网站配置工具
- 详解Asp.net Core 使用Redis存储Session
- ASP.NET Core 使用Redis存储Session
- asp.net SessionState的sqlserver模式的配置及使用
- asp.net网站使用URLRewriter后在iis7.0中的配置
- 在Visual Studia2013中使用ASP.NET网站配置工具
- VS2012 未能将网站XXX配置为使用ASP.NET 4.5.为了使此网站正确运行.你必须将它手动配置为使用ASP.NET 4.5
- 300万PV的ASP.NET网站使用阿里云的配置建议
- win7 2008 尚未在 Web 服务器上注册ASP.NET 4.0。为了使网站正确运行,可能需要手动将 Web 服务器配置为使用 ASP.NET 4.0,按 F1 可了解更多详细信息。
- VS 2012打开提示 未能将网站×××配置为使用 ASP.NET 4.5 和 尚未在Web服务器上注册,您需要手动将Web服务器配置为使用ASP.NET 4.5