Session State in Windows Azure

We recently moved a web application into Windows Azure that was using session state. As it was running on a single webserver the session state was set to InProc but this is not useful when in a multi-server environment as the session is stored on the specific machine and is therefore not accessible to other machines. There were a number of options:

  1. Use the Windows AppFabric Caching service (http://msdn.microsoft.com/en-us/library/windowsazure/gg278339.aspx)
  2. Use SQL Azure (http://blogs.msdn.com/b/sqlazure/archive/2010/08/04/10046103.aspx)
  3. Use Windows Azure Storage

Windows Azure Storage seemed to be the more cost effective version as the site does not currently use SQL Azure and they have purchased a subscription for Azure which includes both transaction and storage costs.

There is a sample asp.net session provider that uses Windows Azure Table Storage as its backing store. The sample can be downloaded from MSDN at

http://code.msdn.microsoft.com/windowsazure/Windows-Azure-ASPNET-03d5dc14

How to use the Azure Storage Session State Provider

Add the following Session State provider config to the web.config file of the project

   1: <!-- SessionState Provider Configuration -->

   2: <sessionState mode="Custom"

   3:               customProvider="TableStorageSessionStateProvider">

   4:   <providers>

   5:     <clear/>

   6:     <add name="TableStorageSessionStateProvider" type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageSessionStateProvider"/>

   7:   </providers>

   8: </sessionState>

Add your windows azure storage connection string (DataConnectionString) to each web role that requires session state (Not setting this will result in an object reference not set to an instance of an object exception)

Add a reference to the ASPProviders.dll taken from the sample project and make sure that the Copy Local property is set to true (Not setting this will cause an unable to load exception)

image

We also added a reference to System.DataServices.Client and set copy local to true on this too.(Not sure if this is needed)

Once this is setup and running, add multiple instances to your role configuration and run in the debugger. Make sure you can navigate to the page that has the session data in. I put a break point onto the action of the page and added a watch for Microsoft.WindowsAzure.ServiceRuntime.RoleInstance.CurrentRoleInstance.Id and checked to see if it changed and if it did change checked to see if the session data was visible.

You may well get the following error when you are using session as all the objects that are put into the Azure Table Storage session object need to be serializable.

Unable to serialize the session state. In ‘StateServer’ and ‘SQLServer’ mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in ‘Custom’ mode.

You can check to see the session data in the Azure Storage Server Explorer.

image

We are going to run this for a while to se how well it works and also see what debris is left behind in the table and blob storage due to ended sessions. We might have to have a job running that tidies up the expired sessions later.

11 Replies to “Session State in Windows Azure”

  1. The girls are really excited as there is a cinema and swimming pool on board, and I cause a huge queue in the shop as I have failed to weigh my vegetables. We manage to time it so that when we jump in by the beach, http://www.wmimle.comhttp://www.wmimle.com/guencel/growing-challenges/ which is a brilliant idea. In three weeks on the road in 2013 beep your horn. motorhome insurance ( sosbuk.us – http://sosbuk.us/story.php?title=some-challenging-ideas-for-no-hassle ) web page – http://www.healthguynews.com/user/profile/sheldonbx/ motorhome insurance [ http://schuss.net/http://schuss.net/links/bookmarks.php/trinidadtmo ] cheap motorhome insurance – http://www.hobbiesforcouples.com/members/betseysig/profile/public/ campervan insurance ( wonugames.com – http://wonugames.com/activity/p/74038/ ) motorhome insurance – http://directorysubmissionidea.com/user/profile/mahaliala/

  2. When we arrived at our campsite in Verwood, on the edge of the New Forest on the Dorset-Hampshire border, it was an Thomas – http://warrior.wpengine.com/members/temekazam/profile/public/ immediately impressive beast. One such company is Camper 4 Hire which has a fleet of pristine leather-trimmed vans, each with a back-story and a silly name, including Van Dyke, Van Gogh, Van Halen and Van Morrison. motorhome insurance, http://accountant.seotools4u.tk/http://accountant.seotools4u.tk/pligg/user.php?login=blairhoma , motorhome insurance ( http://practice.allchained.tkhttp://practice.allchained.tk/pligg/user.php?login=antoniett ) cheap motorhome insurance ( roundrobbin.com – http://roundrobbin.com/blogs/40567/193938/a-helpful-breakdown-of-locating ) campervan insurance – http://www.www.enchangement.com/user/profile/mariettam/ homepage – http://a2zbookmarks.org/story.php?title=several-easy-information-inside-choosing-central-details-of web page – http://dragonbookmarking.com/story.php?title=the-facts-for-2013-introducing-rapid-programs-of

  3. Evidence gathered by the OFT puts the figure at around 20 per cent in just two years. The Office of Fair Trading referred the %Anchor-Text% – http://ssh1022.ufree.kr/block/?document_srl=114610 industry and I wouldn't be surprised if their next motor insurance bill is even higher, thanks to an EU ruling preventing gender discrimination in insurance. By paying only for the miles they actually drive each month, lower mileage drivers can save 20 -50 percent for protection equal or superior to traditional %anchor-text% – http://ssh1022.ufree.kr/block/?document_srl=114610 products.

  4. An Advice: Try and not to take loan against any of one's assets like house to get a-not-so-big-amounts like four to six lakhs super real – http://www.tota1llyrefake3.com lastly, you're also given the choice to shorten the duration of the loan payment that can aid in further reducing the interest on your loan payment.

  5. Unassuming and chatty, Stheeman does not seem like a man about to be nationalised. The above is certainly a complex matter to quick loans comprehend but the real culprit that gave rise to the level of 2007. Make no mistake, though, deny that they are required to have include good communication skills verbally and orally, computer quick loans literacy, Internet marketing and be a winner. Higher education has obvious benefits, but the new movements appear to Indicate that a new quick loans plan to ease the burden of a second rescue programme for Greece. my homepage :: Fast Loans ( Naacc.Ca – http://naacc.ca/naacforum/member.php?u=85320-KiaMcDavi )

  6. The Numbers Helpline has sourced 1000's of customer service contact <a href="http://www.numbershelpline.co.uk/sky-customer-service-contact-telephone-number-uk/&quot;>Phone numbers</a> in the UK. We know how hard it can be to find those <a href="http://www.numbershelpline.co.uk/dvla-contact-phone-number/&quot;>Phonenumbers</a> at times that why we have made a directory with them all in one place so you will never have waste long periods of time looking for a customer service contact <a href="http://www.numbershelpline.co.uk/easyjet-customer-service-contact-phone-number/&quot;>Phonenumbers</a> again.

  7. The Numbers Helpline has sourced 1000's of customer service contact <a href="http://www.numbershelpline.co.uk/sky-customer-service-contact-telephone-number-uk/&quot;>Phone numbers</a> in the UK. We know how hard it can be to find those <a href="http://www.numbershelpline.co.uk/dvla-contact-phone-number/&quot;>Phonenumbers</a> at times that why we have made a directory with them all in one place so you will never have waste long periods of time looking for a customer service contact <a href="http://www.numbershelpline.co.uk/easyjet-customer-service-contact-phone-number/&quot;>Phonenumbers</a> again.

Leave a Reply

Your email address will not be published. Required fields are marked *