在Azure云服务中启用同位置会话缓存

时间:2014-01-07 05:39:33

标签: asp.net asp.net-mvc session caching azure

现在我有一个Azure Cloud Service托管MVC应用程序 - 当前 - 使用Staging<>中的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应用程序)时,我收到以下错误:

  

发现或指定的地址都不匹配套接字地址   家庭。参数名称:context

我在这里没有太多细节,只是在Source Not Available窗口中被抛出。

因此,我认为这可能只是一个我可以在以后担心的本地问题,我发布到Azure。该应用运行正常。但是部署和VIP交换会中断会话,因此它似乎无法正常工作。

可能导致这种情况的原因是什么?我试图准确地遵循所有指示。

我注意到的一件事是,链接到的最后一篇文章来自Azure缓存教程 - 我从未设置Azure缓存,因为我使用的是具有我的共同角色的存储帐户(根据上一个教程)。可能导致这些问题的原因是什么?

1 个答案:

答案 0 :(得分:3)

是的,我认为你遇到的是正确的。

首先,您的本地测试失败是因为您启动了MVC应用程序。这样,您的应用程序在没有azure仿真器的情况下运行,这意味着缓存客户端无法从您在web.config中指定的角色名称identifier部分找到缓存端点。我认为如果你在本地模拟器上运行你的应用程序它应该可以工作。

其次,当您交换VIP时,您的会话应该丢失。角色内缓存利用您的一些角色实例的内存。当您交换VIP时,公共IP将被配置到另一个插槽,这意味着您的缓存实例也将被切换。要解决此问题,我希望您尝试新的缓存服务(预览)。通过这种方式,您可以为订阅创建专用缓存,以便可以在云服务部署,虚拟机和网站中使用它们。

希望这有帮助。