locked
Azure and ASP.NET MVC session storage. RRS feed

  • Question

  • Hello,

    I have a web role with several instances that needs to share session data.

    How do I achieve this in Azure?

    I want to be able to use ASP.NET MVC features like VIEWBAG and VIEWDATA as if I’m coding for a regular one instance MVC application.

    Is this possible?

    What kind of configuration must I perform in web.config to achieve this?

    Thank you all!
    • Edited by Igit Friday, January 6, 2012 10:55 PM
    Friday, January 6, 2012 10:54 PM

Answers

  •  

    Do you use SQL Azure in your project? If so, I think ASP.NET Universal Providers [1] would be a good option to consider. The "DefaultSessionStateProvider" should allow you to use SQL Azure in a similar way to the traditional SQL Session State Provider.

     

    It will save you $ costs associated with AppFabric Caching, if your application and SQL Azure database are hosted on the same data center.

     

    [1] http://nuget.org/packages/System.Web.Providers

    [2] http://www.hanselman.com/blog/IntroducingSystemWebProvidersASPNETUniversalProvidersForSessionMembershipRolesAndUserProfileOnSQLCompactAndSQLAzure.aspx


    Srini
    • Marked as answer by Arwind - MSFT Thursday, January 12, 2012 2:42 AM
    Sunday, January 8, 2012 10:33 AM
  • You could use Windows Azure AppFabric Caching for session state:  http://msdn.microsoft.com/en-us/gg457897

    Cheers

    Friday, January 6, 2012 11:43 PM
  • Agree with BaileAthaAbu, you can use Windows Azure AppFabric Cache. And you can set your session provider by using the configuration.

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

    <!-- Cache exposes two endpoints: one simple and other SSL endpoint. Choose the appropriate endpoint depending on your security needs. -->

    <dataCacheClients>

     

      <dataCacheClient name="default">

        <hosts>

          <host name="shaunxu-caching.cache.windows.net" cachePort="22233" />

        </hosts>

     

        <securityProperties mode="Message">

          <messageSecurity 

            authorizationInfo="XXXXXXXX"

          </messageSecurity>

        </securityProperties>

      </dataCacheClient>

    </dataCacheClients>

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

      <providers>

        <add name="AppFabricCacheSessionStoreProvider"

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

             cacheName="default"

             useBlobMode="true"

             dataCacheClientName="default" />

      </providers>

    </sessionState>

    • Marked as answer by Arwind - MSFT Thursday, January 12, 2012 2:41 AM
    Saturday, January 7, 2012 7:21 AM

All replies

  • You could use Windows Azure AppFabric Caching for session state:  http://msdn.microsoft.com/en-us/gg457897

    Cheers

    Friday, January 6, 2012 11:43 PM
  • Agree with BaileAthaAbu, you can use Windows Azure AppFabric Cache. And you can set your session provider by using the configuration.

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

    <!-- Cache exposes two endpoints: one simple and other SSL endpoint. Choose the appropriate endpoint depending on your security needs. -->

    <dataCacheClients>

     

      <dataCacheClient name="default">

        <hosts>

          <host name="shaunxu-caching.cache.windows.net" cachePort="22233" />

        </hosts>

     

        <securityProperties mode="Message">

          <messageSecurity 

            authorizationInfo="XXXXXXXX"

          </messageSecurity>

        </securityProperties>

      </dataCacheClient>

    </dataCacheClients>

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

      <providers>

        <add name="AppFabricCacheSessionStoreProvider"

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

             cacheName="default"

             useBlobMode="true"

             dataCacheClientName="default" />

      </providers>

    </sessionState>

    • Marked as answer by Arwind - MSFT Thursday, January 12, 2012 2:41 AM
    Saturday, January 7, 2012 7:21 AM
  •  

    Do you use SQL Azure in your project? If so, I think ASP.NET Universal Providers [1] would be a good option to consider. The "DefaultSessionStateProvider" should allow you to use SQL Azure in a similar way to the traditional SQL Session State Provider.

     

    It will save you $ costs associated with AppFabric Caching, if your application and SQL Azure database are hosted on the same data center.

     

    [1] http://nuget.org/packages/System.Web.Providers

    [2] http://www.hanselman.com/blog/IntroducingSystemWebProvidersASPNETUniversalProvidersForSessionMembershipRolesAndUserProfileOnSQLCompactAndSQLAzure.aspx


    Srini
    • Marked as answer by Arwind - MSFT Thursday, January 12, 2012 2:42 AM
    Sunday, January 8, 2012 10:33 AM