简体   繁体   中英

Avoid deleting files on Azure Cloud Service publish

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.

项目文件夹结构

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

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.

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.

转到发布设置 - >展开文件发布选项 - >并取消选中“删除目的地中的其他文件”框。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM