Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

asp.net - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...