none
AppFabric ASP.NET Session State Caching not working with 2 Instances on local Development Fabric Compute Emulator RRS feed

  • Question

  • Windows Azure AppFabric provides the caching service to enable distributed load-balanced ASP.NET session state.

    I noticed a problem when using 2 (small or medium) web role instances and testing it in the local development fabric compute emulator configured to use the cache service in the cloud. What gives me back the same correct session values on every instance in production in the cloud returns different values on the local fabric!

    My configuration in the web.config is the following:

      <configSections>

        <!-- Append below entry to configSections. Do not overwrite the full section. -->

        <section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core"

                 allowLocation="true" allowDefinition="Everywhere"/>

      </configSections>

     

      <dataCacheClients>

     

        <dataCacheClient name="default">

          <hosts>

            <host name="mycache.cache.windows.net" cachePort="22233" />

          </hosts>

     

          <securityProperties mode="Message">

            <messageSecurity

              authorizationInfo="key...==">

            </messageSecurity>

          </securityProperties>

        </dataCacheClient>

     

      </dataCacheClients>

     

      <system.web>

     

        <compilation debug="true" targetFramework="4.0" />

        <!--<sessionState mode="InProc" customProvider="DefaultSessionProvider">

          <providers>

            <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />

          </providers>

        </sessionState>-->

        <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">

          <providers>

            <clear/>

            <add name="AppFabricCacheSessionStoreProvider"

                 type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"

                 cacheName="default"

                 useBlobMode="true"

                 dataCacheClientName="default" />

          </providers>

        </sessionState>

    ...

    See details here.

    Can somebody confirm this to be a problem?

    Friday, November 25, 2011 9:04 AM

All replies

  • Hi,

    According to your description, I would like to suggest you to configure sharedId, then the multiple instances can share the session data.

    You can refer to the article below for the detailed information:

    http://msdn.microsoft.com/en-us/library/ee790859.aspx

     

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    Monday, November 28, 2011 6:06 AM
    Moderator
  • Hi Ming

    Please note, I'm asking about Window Azure ASP.NET session state caching using Azure Cache (the link would be http://msdn.microsoft.com/en-us/library/windowsazure/gg278339.aspx) and not about Windows Server AppFabric session state.

    Azure AppFabric Cache uses Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider and 
    Windows Server AppFabric Cache uses Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider

    I tried the sharedId attribute

    <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">

          <providers>

            <add name="AppFabricCacheSessionStoreProvider"

                 type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"

                 cacheName="default"

                 useBlobMode="true"

                 dataCacheClientName="default"

                 sharedId="myApp" />

          </providers>

        </sessionState>

      

     

    But still the same problem.

     

    Do I need to use the Windows Server AppFabric Cache Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider when testing Azure AppFabric Caching on the local machine? Should the sharedId also work on DistributedCacheSessionStateStoreProvider? What's the recommended best practice then to switch between Local and Cloud web.config settings then?

    Thanks,

    Markus

    Wednesday, November 30, 2011 10:54 AM
  • Playing around and replaced the Azure AppFabric session state provider with the Windows Server AppFabric session state provider (which I have also installed on my Windows 7 machine) gave me back the expected session value independant of the local development fabric web role instance!

    But as I am not using it from "multiple Web applications" but from the one and only - I do not even need the sharedId attribute for it to work.

    So the finding is: the Azure AppFabric session state provider Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider must be replaced with the Server AppFabric session state provider Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider when running several instances on the local compute emulator.

    This is very nasty. Any more ideas?

    Wednesday, November 30, 2011 11:16 AM
  • Thanks for reporting this issue. I just tried it on my side, and I can reproduce it. I'll forward it to the caching team.
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    Wednesday, November 30, 2011 2:15 PM
    Moderator
  • i too facing the same issue developed a shopping cart application.stored the cart in session.used windows azure app fabric  as session state provider.I tested application locally using real azure app fabric credential given by Microsoft azure plat form.When run with multiple instances application lost the cart stored in session. 
    Wednesday, December 7, 2011 5:32 AM
  • I think this is something to do with the way development emulator runs the multiple instances of the application. By default site name is considered as applicationName for the caching hence multiple instnaces would be considered as separate applicaitons and hence would not be able to share the session. To fix this you can try explicitly providing applicationName attribute (which is a good practice anways) in provider setting in web.config file as indicated below :
    <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
        <providers>
          <add name="AppFabricCacheSessionStoreProvider"
                type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"
                cacheName="default"
                applicationName=“demo101”
               dataCacheClientName="default" />
        </providers>
      </sessionState>
    
    

    Monday, December 19, 2011 5:21 AM
  • Hi

    Adding the application Name in the as suggested above worked for me, but need to check it once the application is ported to Cloud.

    I am getting one more issue here, please let me know if any one is getting the same, as we all know most the people prefer using Firefox for web applications.

    For our product the primary web browser target is firefox, i am getting this unknow issues while i was trying to suspend the service as give here (http://msdn.microsoft.com/en-us/gg457897) to test the azure appfarbic caching session state scenario. The whole service is getting destroyed and removed from the emulator interface, any one have idea of how to resolved this issues in firefox 4.0 version.  The same i working fine with IE.

    Thanks in advance.

    Monday, March 5, 2012 9:48 AM
  • I don't think you should worry about an issue occuring in firefox while suspending a service from emulator, might be some integration issue of emulator with Firefox.


    -Sachin Sancheti

    Monday, March 5, 2012 11:09 AM
  • Thanks for reporting this issue. I just tried it on my side, and I can reproduce it. I'll forward it to the caching team.
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    the issue is not only with appfabric caching but with other sessions providers such as SQL Azure. While running multiple instances locally each instance creates a seperate session no matter if it uses SQL Azure or AppFabric Caching.

    If this post answers your question, please mark it as an answer. If this post is helpful to you, then vote it as helpful.
    TechyFreak | Mobile Development Resources

    Monday, March 5, 2012 2:14 PM
  • Hi 

    Sachin and Techyfreak

    Thanks for your reply, but we used to test the application in firefox only during our development and dont use IE while developing, Hope the Caching Team resolves this issue.

    Monday, March 5, 2012 5:06 PM
  • I think this is something to do with the way development emulator runs the multiple instances of the application. By default site name is considered as applicationName for the caching hence multiple instnaces would be considered as separate applicaitons and hence would not be able to share the session. To fix this you can try explicitly providing applicationName attribute (which is a good practice anways) in provider setting in web.config file as indicated below :
    <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
        <providers>
          <add name="AppFabricCacheSessionStoreProvider"
                type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"
                cacheName="default"
                applicationName=“demo101”
               dataCacheClientName="default" />
        </providers>
      </sessionState>
    
    

    Adding the applicationName attribute to sessionstate entry seems to work for us when developing using the compute emulator.(maybe someone can mark Sachins solution as the answer until a perm fix is ready).


    • Edited by ShinyPixels Saturday, March 10, 2012 12:30 AM
    Saturday, March 10, 2012 12:29 AM
  • Wow I could not figure out what the heck was going on. Thanks, giving the applicationName fixed it.
    Friday, April 6, 2012 10:29 PM