简体   繁体   English

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

[英]Enabling co-located Session Caching in an Azure Cloud Service

Right now I have an Azure Cloud Service hosting an MVC app that - currently - when updated using the VIP swap method from Staging <> Production, kills all sessions. 现在我有一个Azure Cloud Service托管一个MVC应用程序 - 当前 - 当使用Staging <> Production的VIP交换方法更新时,会杀死所有会话。 I haven't done any configuration around Session management, so this is to be expected. 我没有围绕会话管理做任何配置,所以这是可以预期的。

I'm now trying to address this by following this link: 我现在正试图通过以下链接解决这个问题:

http://www.windowsazure.com/en-us/manage/services/cache/net/how-to-in-role-cache/ http://www.windowsazure.com/en-us/manage/services/cache/net/how-to-in-role-cache/

I've enabled in-role caching. 我启用了角色内缓存。 My dataCacheCLients looks like this: 我的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>

The above link points here to actually set the web.config for session caching: 以上链接指向实际设置会话缓存的web.config:

http://www.windowsazure.com/en-us/manage/services/cache/net/how-to-in-role-cache/#store-session http://www.windowsazure.com/en-us/manage/services/cache/net/how-to-in-role-cache/#store-session

I've uncommented that section (just session caching) in my web.config, which now looks like this: 我在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>-->

Now, when I run this locally (no emulators used, just the MVC app in IIS), I get the following error: 现在,当我在本地运行它(没有使用模拟器,只是IIS中的MVC应用程序)时,我收到以下错误:

None of the discovered or specified addresses match the socket address family. 发现的或指定的地址都不匹配套接字地址族。 Parameter name: context 参数名称:context

I don't get much in the way of details here, it just gets thrown in a Source Not Available window. 我在这里没有太多细节,它只是被抛入Source Not Available窗口。

So, thinking that this might just be a local issue that I can worry about later, I published to Azure. 因此,我认为这可能只是一个我可以在以后担心的本地问题,我发布到Azure。 The app runs fine. 该应用运行正常。 But deploying and VIP swapping breaks sessions, so it appears to not be working. 但是部署和VIP交换会中断会话,因此它似乎无法正常工作。

What could be causing this? 可能是什么导致了这个? I've attempted to follow all instructions precisely. 我试图准确地遵循所有指示。

One thing I noticed is that the last article linked to is from the Azure Cache tutorial - I never set up Azure Cache, as I'm using a storage account with my co-located role (per the previous tutorial). 我注意到的一件事是,链接到的最后一篇文章来自Azure缓存教程 - 我从未设置Azure缓存,因为我使用的是具有我的共同角色的存储帐户(根据前面的教程)。 What could be causing these issues? 什么可能导致这些问题?

Yes I think what you met with is correct. 是的,我认为你遇到的是正确的。

First, your local test failed was because you started your MVC application. 首先,您的本地测试失败是因为您启动了MVC应用程序。 In this way your application ran without azure emulator which means the cache client cannot find the cache endpoint from the role name ( identifier part you specified in web.config). 这样,您的应用程序在没有azure仿真器的情况下运行,这意味着缓存客户端无法从角色名称(您在web.config中指定的identifier部分)中找到缓存端点。 I think it should work if you run your application on local emulator. 我认为如果你在本地模拟器上运行你的应用程序它应该工作。

Second, when you swapped VIP your session should be lost. 其次,当您交换VIP时,您的会话应该丢失。 In-Role cache utilizes some of your role instances' memory. 角色内缓存利用您的一些角色实例的内存。 When you swapped VIP, the public IP will be configured to another slot which means your cache instances will be switched as well. 当您交换VIP时,公共IP将被配置到另一个插槽,这意味着您的缓存实例也将被切换。 To fix this problem, I'd like you to try the new Cache Service (Preview). 要解决此问题,我希望您尝试新的缓存服务(预览)。 In this way you create dedicate cache for your subscription so that you can use them across cloud service deployments, virtual machines and websites. 通过这种方式,您可以为订阅创建专用缓存,以便您可以在云服务部署,虚拟机和网站中使用它们。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM