【发布时间】:2014-01-07 05:39:33
【问题描述】:
现在我有一个托管 MVC 应用程序的 Azure 云服务 - 当前 - 当使用 Staging Production 中的 VIP 交换方法进行更新时,会终止所有会话。我没有对会话管理进行任何配置,所以这是可以预料的。
我现在正在尝试通过以下链接来解决这个问题:
http://www.windowsazure.com/en-us/manage/services/cache/net/how-to-in-role-cache/
我已启用角色内缓存。我的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>
以上链接指向此处实际设置 web.config 以进行会话缓存:
http://www.windowsazure.com/en-us/manage/services/cache/net/how-to-in-role-cache/#store-session
我在我的 web.config 中取消了该部分(只是会话缓存)的注释,现在看起来像这样:
<!-- 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 应用程序),我收到以下错误:
发现的或指定的地址都不匹配套接字地址 家庭。参数名称:上下文
我在这里没有太多细节,它只是被扔进了Source Not Available 窗口。
因此,考虑到这可能只是我以后可以担心的本地问题,我将其发布到 Azure。该应用程序运行良好。但是部署和 VIP 交换会中断会话,因此它似乎无法正常工作。
这可能是什么原因造成的?我试图准确地遵循所有说明。
我注意到的一件事是链接到的最后一篇文章来自 Azure 缓存教程 - 我从未设置 Azure 缓存,因为我使用的是存储帐户和我的并置角色(根据上一个教程)。什么可能导致这些问题?
【问题讨论】:
-
我想强调 Shaun Xu 提出的重要观点 - 使用角色内缓存无法解决会话在 VIP 交换上丢失的情况,因为您将更改为您的用户服务的实例并有效地引入一个新的缓存。要避免这种情况,请使用新的缓存服务或使用数据库会话提供程序。
-
您必须考虑以下几点 - 1) 如果正常的 Session 停留在 RAM 上,那么 In-Role Cache 也会在 RAM 上。因此,当您进行 VIP 交换时,正常会话会消失,并且与角色内缓存相同。 2)如果将来您要对服务进行负载平衡怎么办,在这种情况下,除非您选择 Session Affinity,否则角色内缓存将不起作用。所以根据上面的说法,可以想到Azure Cache服务。windowsazure.com/en-us/manage/services/cache/net/…
标签: asp.net asp.net-mvc session caching azure