Search code examples
asp.net-mvcazureazure-web-app-serviceblobstorage

What folder in asp MVC Web Sites are accessible to store and retrieve files apart from App_Data when hosted in Azure Web Sites?


I just finished my asp MVC 5 website that has capability to upload, display and download file. While offline, I uploaded the files to a random foldes inside the root directory like ~/assest/images etc and worked great.

Then I deployed to the windows Azure Web site service, and started to realize that the root directory is not accessible anymore. I started to do researches and found out that only App_Data is accesible to store files. Alas, it is not a good solution and we cannot retrive the file, like image, to be shown in razor view.

I also found BLOB Storage, which seems to be great, but there is no sufficent tutorial, that I could not succeed to use one. Most of them are for MVC web roles, while in my case it is MVC WEB SITES.

Now, I want to find another alternative, is there any special folder, or workaround to make one folded inside the root directory that can store files and retrieve them? in fact, my application needs only a few pictures and PDF to store.

thanks


Solution

  • You shouldn't be using App_Data to store uploaded files using Azure Web Sites. You only get a limited amount of space, and if you scale your site to more instances, the uploaded files will only be available on the instance where they were uploaded!

    The correct way to handle uploaded files is indeed to use Blob storage. You can use this easily from your web site. Just install the Azure .NET Storage Client Library (this is available from Nuget).

    There is a full tutorial on using the Azure .NET Storage Client Library at http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs/

    You can easily display uploaded images on your site by making the blob container public. Then you can link directly to an image within your blob container - it will have a URL like

    https:// your storage account name .blob.core.windows.net/ your blob container name /filename.jpg