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. 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/

I’ve enabled in-role caching. My dataCacheCLients looks like this:

<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:

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:

 <!-- 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:

None of the discovered or specified addresses match the socket address
family. Parameter name: context

I don’t get much in the way of details here, it just gets thrown in a Source Not Available window.

So, thinking that this might just be a local issue that I can worry about later, I published to Azure. The app runs fine. But deploying and VIP swapping breaks sessions, so it appears to not be working.

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). What could be causing these issues?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Yes I think what you met with is correct.

First, your local test failed was because you started your MVC application. 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). I think it should work if you run your application on local emulator.

Second, when you swapped VIP your session should be lost. 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. 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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x