Asp.net 在Azure云服务中启用共址会话缓存
现在我有一个Azure云服务,它托管一个MVC应用程序,当前,当使用VIP交换方法从暂存生产中更新时,会终止所有会话。我还没有对会话管理进行任何配置,所以这是意料之中的 我现在尝试通过以下链接解决此问题: 我已经启用了角色缓存。我的Asp.net 在Azure云服务中启用共址会话缓存,asp.net,asp.net-mvc,session,caching,azure,Asp.net,Asp.net Mvc,Session,Caching,Azure,现在我有一个Azure云服务,它托管一个MVC应用程序,当前,当使用VIP交换方法从暂存生产中更新时,会终止所有会话。我还没有对会话管理进行任何配置,所以这是意料之中的 我现在尝试通过以下链接解决此问题: 我已经启用了角色缓存。我的dataCacheCLients如下所示: <dataCacheClients> <dataCacheClient name="default"> <!--To use the in-role flavor of W
dataCacheCLients
如下所示:
<dataCacheClients>
<dataCacheClient name="default">
<!--To use the in-role flavor of Windows Azure Cache, set identifier to be the cache cluster role name -->
<!--To use the Windows Azure Cache Service, set identifier to be the endpoint of the cache cluster -->
<autoDiscover isEnabled="true" identifier="MyRoleName" />
</dataCacheClient>
</dataCacheClients>
<!-- Windows Azure Cache 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>
<!-- Windows Azure Cache output cache provider -->
<!--Uncomment this section to use Windows Azure Cache for output cache-->
<!--<caching>
<outputCache defaultProvider="AFCacheOutputCacheProvider">
<providers>
<add name="AFCacheOutputCacheProvider" type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache" cacheName="default" dataCacheClientName="default" applicationName="AFCacheOutputCache" />
</providers>
</outputCache>
</caching>-->
我已经在我的web.config中取消了该部分的注释(只是会话缓存),现在看起来如下所示:
<dataCacheClients>
<dataCacheClient name="default">
<!--To use the in-role flavor of Windows Azure Cache, set identifier to be the cache cluster role name -->
<!--To use the Windows Azure Cache Service, set identifier to be the endpoint of the cache cluster -->
<autoDiscover isEnabled="true" identifier="MyRoleName" />
</dataCacheClient>
</dataCacheClients>
<!-- Windows Azure Cache 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>
<!-- Windows Azure Cache output cache provider -->
<!--Uncomment this section to use Windows Azure Cache for output cache-->
<!--<caching>
<outputCache defaultProvider="AFCacheOutputCacheProvider">
<providers>
<add name="AFCacheOutputCacheProvider" type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache" cacheName="default" dataCacheClientName="default" applicationName="AFCacheOutputCache" />
</providers>
</outputCache>
</caching>-->
现在,当我在本地运行此应用程序时(没有使用模拟器,只有IIS中的MVC应用程序),我得到以下错误:
发现的或指定的地址都与套接字地址不匹配
家庭参数名称:上下文
我在这里不了解太多细节,它只是被扔到一个源代码不可用的窗口中
所以,考虑到这可能只是一个我以后可以担心的本地问题,我发布到Azure。应用程序运行良好。但部署和VIP交换会中断会话,因此它似乎无法工作
这可能是什么原因造成的?我已经试着完全按照指示去做了
我注意到的一件事是,链接到的最后一篇文章来自Azure缓存教程-我从未设置Azure缓存,因为我使用的存储帐户与我的共同定位角色(根据上一篇教程)。是什么导致了这些问题?是的,我认为您遇到的是正确的
首先,您的本地测试失败是因为您启动了MVC应用程序。这样,您的应用程序在没有azure emulator的情况下运行,这意味着缓存客户端无法从角色名(identifier
您在web.config中指定的部分)中找到缓存端点。我认为如果您在本地模拟器上运行应用程序,它应该可以工作
第二,当您交换VIP时,您的会话应该会丢失。角色内缓存利用一些角色实例的内存。当您交换VIP时,公共IP将被配置到另一个插槽,这意味着您的缓存实例也将被交换。要解决此问题,我希望您尝试新的缓存服务(预览)。通过这种方式,您可以为订阅创建专用缓存,以便跨云服务部署、虚拟机和网站使用它们
希望这能有所帮助。我想强调Shaun Xu提出的一个重要观点-使用角色缓存无法解决VIP交换时会话丢失的问题,因为您将更改为用户服务的实例,从而有效地引入新的缓存。要避免这种情况,请使用新的缓存服务或使用数据库会话提供程序。您必须考虑以下几点-1)如果正常会话保留在RAM上,则角色内缓存也将保留在RAM上。所以,当您进行VIP交换时,正常会话将消失,与角色缓存中的会话相同。2) 如果将来您要平衡服务的负载,在这种情况下,除非您选择会话关联,否则角色内缓存将无法工作。因此,基于以上陈述,您可以想到Azure缓存服务。