5

I'm hosting my ASP.NET MVC applications as Azure Cloud Service.

I encountered a problem deleting pictures, which uploaded by user, after new deployment.

Uploaded pictures are saving into the custom special folder WebProject/UserFiles/MedicalCenterImages

Below I've provided my project folder structure.

Project folder structure

I've found and investigated several questions related to my

and figure out, that I should to add a SkipDelete rule on the .csproj file.

<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
  <MsDeploySkipRules Include="SkipUserFilesFolder">
    <SkipAction>Delete</SkipAction>
    <ObjectName>filePath</ObjectName>
    <AbsolutePath>UserFiles</AbsolutePath>
  </MsDeploySkipRules>
</ItemGroup>
</Target>

but I don't fully understand which file I should to edit in my case? (MaxPatient.Web.csproj or MaxPatientCloudService.ccproj or any another file)

I always publishing my MaxPatientCloudService project.

I will be grateful for any help.

Thanks :)

Community
  • 1
  • 1
Artyom Pranovich
  • 6,814
  • 8
  • 41
  • 60

4 Answers4

9

Azure Cloud Service deployments typically (staging slot with a VIP swap to prod slot) create new virtual machines (VMs). You can only plan on content files in the actual MVC project to get deployed to the new VMs. User uploads won't survive a deployment. You need to store uploaded files in Azure BLOBs, database or use an Azure website instead of a Cloud Service.

viperguynaz
  • 12,044
  • 4
  • 30
  • 41
  • Thanks for your answer. Is it turns out that after each deployment (as Cloud Service) Azure creates a new VM, re-configures IIS and publish application on it? – Artyom Pranovich Oct 14 '14 at 16:54
  • Yes - the deployment runs a full provisioning on new VMs to install and configure IIS then add the website or web service (worker role) to IIS. – viperguynaz Oct 14 '14 at 20:42
  • 1
    This is not right. We save all our userdata and it works alright. I ran into this issue once but soon realized that it was a problem with the file publish settings. Go to Publish Settings -> Expand File Publish Options -> And Untick the box that says remove additional files at destination. – Amitesh Apr 02 '15 at 05:53
  • @Amitesh: It may be true that the data persists between updates, but you are playing a dangerous game. Any Guest OS update (roughly once per month) or a VM hardware failure will cause the VM to be reprovisioned and all user-generated content on the local disk will be permanently lost. You should definitely be using Azure BLOB storage or some derivative (e.g., page-blob backed vhd that you attach OnStart). – mellamokb Aug 25 '15 at 14:58
  • @mellamokb I have implemented my all code. Cannot change to work it with azure blob storages. Dont we have another alternative ? Everytime my images gets deleted. If i upload my content via RDP, it also gets reverted in few days. Thanks for your help! – Rohit Arora Aug 26 '15 at 04:25
  • @RohitArora: If you can at least point it to a network path (or even symlink it so it's the same path!), then try the [Azure Files Preview](http://azure.microsoft.com/en-us/updates/preview-azure-files/). Note that as a Preview feature it is still subject to change and may not work 100% correctly until it's GA. – mellamokb Aug 26 '15 at 04:26
  • @mellamokb If the VM is reprovisioned then the website itself will be re-deployed, then where is the "prototype" website data stored and how is it different than the files being used by the actual working website? – Dai May 10 '16 at 02:37
2

Whenever you publish to Azure Cloud Service, new VM is created. If I want Azure not to delete a blank folder, I normally add a dummy file inside the folder.

Ideally, you want to punish to Staging. Then SWAP Staging with Production so that you can minimize the downtime of our site.

In addition, you need at least two instances in Azure Cloud Service. One instance cannot access folder inside other instances.

Uploaded pictures are saving into the custom special folder WebProject/UserFiles/MedicalCenterImages

For scenario, you need to save customer images in Blob Storage (or SQL Azure), so that all instances can read/write the image.

Note: when Azure recycles an instance (whatever reason), it creates a new VM from original uploaded package. Therefore, we should never save data inside the web server's folders.

Win
  • 61,100
  • 13
  • 102
  • 181
0

Go to Publish Settings -> Expand File Publish Options -> And Untick the box that says remove additional files at destination.

Amitesh
  • 113
  • 2
  • 10
0

I am not sure if this works for continuous deployment but a solution with manual deployment from VS is to put the server files you want to keep in the App_Data folder.

The standard publish settings for VS / Azure allow you to:

"Remove additional files at destination" and "Exclude files in the App_Data folder"

This means that you can clear redundant project files in the project without affecting files and data that is specific in the live application

A possible downside will be restriction of public access to App_Data and use of the App_Data folder for general storage purposes - see also this post about that issue.

Images that are in App_Data folder not shown in browser

Community
  • 1
  • 1
Xcheque
  • 583
  • 1
  • 5
  • 14