Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Hosted-services / Azure

How to Access Blob Storage from an Azure Web Site

3.40/5 (3 votes)
7 Jan 2016CPOL2 min read 9.6K  
We recently encountered the dreaded 'Not running in a hosted service or the Development Fabric' yellow screen of death whilst developing a client website hosted inside Azure. This post outlines one approach to accessing Blob/Table/Queue Storage services from an Azure Web Site.

I've read a few posts on this error but they've mainly been focused on the development environment, rather than the production environment that I was encountering the issue on. Our scenario is one in which we have discovered the wonders of Git Deploy and the massive time saving association (kudos to Kudu and David Ebbo et al.) that comes with using an Azure Website as opposed to a Web Role within a Cloud Service (a good comparison of the available options can be found here).

Enter Blob Storage, Exit Working Website

Everything was going well until we brought Blob Storage into the equation. The site was running fine locally, the Azure Compute and Storage emulators had been spun up by Visual Studio running as Administrator, so no problems there. Another speedy git deployment (not that I'm a fan or anything) and then wallop. 'Not running in a hosted service or the Development Fabric' when trying to access CloudConfigurationManager.GetSetting. Some general Googling and reading various Stack Overflow posts lead me to the understanding that an Azure Website is effectively Shared Hosting, and as such doesn't run as a dedicated hosted service. There's no ServiceDefinition config so no direct way to access Blob Storage.

By changing the Web Role to be a WCF service purely focused on reading from and writing to Blob Storage instead of the Azure Website as we initially had it set up before getting on to the Git Deployment goodness, we could abstract the communication with Blob Storage away from the Website. It's still painful to publish the WCF Web Role, so we'll probably make use of the Web Accelerator for Web Roles, a useful project on Github.

To sum up, Azure Websites are great for getting a site spun up and deployed quickly provided that you don't need to use Blob/Table/Queue storage, which requires either a Web Role or a site hosted within an Azure VM. Communication with SQL Azure is fine from a Website as it's just a bog standard connection string. In our scenario, a Web Role hosting a WCF service works just fine.

View original article

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)