Avoid deleting files on Azure Cloud Service publish - c#

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
Avoid deleting folder on Web Publish
MSDeploy skip rules when using MSBuild PublishProfile with Visual Studio 2012
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.

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

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

Related

How to edit configuration files (part of Azure Cloud Services (Classic) files )on Remote Desktop?

I have deployed Azure cloud service and it is working. In deployment files, I have app.config. I have to edit app.config and save it. I don't want to re-deploy cloud service again from Visual Studio. I am able to login in remote Desktop but don't know how to view file and then edit file. Any suggestion?
Technically this can be done, but you should not do it except for testing purposes. Any change you make via RDP will be lost and will revert back to whatever you deployed with your CSPKG.
For more information on editing a running cloud service see https://blogs.msdn.microsoft.com/kwill/2013/09/05/how-to-modify-a-running-azure-service/. You can find your config files on E drive or F drive under sitesroot or approot depending on your role type.

Must bin/roslyn be published every time?

I'm publishing over webDav to webserver; the site is both classic asp and new c# aspx.
Currently it is only two pages, but the majority of the time is spent uploading bin/roslyn.
The time of the files in bin/roslyn changes to the time of publish.
Is this upload nessecary every time; does the files really change?
I'm not asking if bin/roslyn can be removed.
Is there a way to just upload the changed files?
I'm uploading over 4G network, while it is not exactly slow, it's not wirespeed either.
I don't uplode the entire website; there are a lot of old .asp and images I haven't pulled to my workstation, so I don't delete the existing files first.
Copying all files to temporary location below for package/publish:
obj\Release\Package\PackageTmp.
Publishing folder /...
Publishing folder bin...
Publishing folder bin/roslyn...
Publishing folder xml...
Web App was published successfully file:///Y:/
I'm not sure how to get a list of all files, but I'll write a few names:
Microsoft.CodeAnalysis.VisualBasic.dll
Microsoft.CodeAnalysis.CSharp.dll
Microsoft.CodeAnalysis.dll
Microsoft.DiaSymReader.Native.amd64.dll
This is in descending size; already this is about 10MB.
I have not used webDav before, but it seems like work the same as ftp publish.
If you want to publish only part which have changed, there is two way:
use web deploy
publish to local file then chose only upload the part has changed
use web deploy
there is article of how to set up web deploy at microsoft docs
https://learn.microsoft.com/en-us/iis/install/installing-publishing-technologies/installing-and-configuring-web-deploy-on-iis-80-or-later
essentially install web deploy at iis, then when publishing in VS, chose web deploy
deploy to local folder then upload change part
in VS, publish to local folder, then manually upload file which have changed (if you use version control, who wouldn't, you should be able to tell which files has changed)

Website on IIS Errors When Listing Directories

I have a VPS (Cloud Server) and I have Visual Studio, IIS, SQL... all those nice things installed. I am also sometimes doing development on this VPS.
This website is basically a simple file manager. When it loads, it lists files and folders that resides in the App_Data folder. This said, I am using the App_Data as my "root/home/topmost-directory" for the file manager.
The reason I am putting them in the App_Data folder is because I don't want users to just go like this: www.mywebsite.com/ROOT/[gets a list of files].
Instead, if they try to go: www.mywebsite.com/App_Data/[tries to get list], IIS will block them with a nice error (because IIS blocks access to that folder).
So, the website accesses the structure in the App_Data folder via code behind. This is how the website navigates. It can download, upload, move files around, rename... delete... everything right to/inside the App_Data folder.
The only problem is, this only works when I run the website in Visual Studio and run my tests, testing the website, debugging, etc. The moment I publish (via File System in Visual Studio) the website to the directory: "C:/inetpub/Sites/[WebsiteFolder]", and navigates to the website's URL, the website does not work any more. It loads, but it does not get the file structure in the App_Data folder any more, it cannot create new folders, cannot rename them...
This website works fine when I upload it via FTP to another webs space that is hosted somewhere else at another hosting company (which is shared hosting).
So I guess (my best guess) the IIS on my VPS does not allow this kind of access. And I have been trying to find settings on IIS somewhere that would/could allow this.
I have enabled directory browsing, but that's probably the only thing I can think of other than making sure the directory is accessible (readable/writable).
Do you perhaps know what else I can try?
Ohkay, so this was a very silly mistake - but that's how we learn!
The App_Data folder did not have any other files or folders inside of it.
And as we know, ASP.NET does not publish empty directories. This means those empty folders never existed once I published the website.
There are 3 ways to fix this that I know of at the moment:
If your solution has a publish profile (so that you can publish the site), you can right click the empty folder in Visual Studio, and say Publish [FolderName] eg:
You can just create an empty file in that directory, and publish your whole website again. Because the folder is not empty any more, it publishes with the rest of the website.
Just manually create the folder on your hosting space.
Thanx for everyone's input!
Greatly appreciated!

How can I use the ExportLogic command in EWL to deploy an application?

What exactly are the steps to take after running ExportLogic in the Package Manager Console? Does this do anything for updating the database on the server?
To deploy an EWL system using ExportLogic, the first step is to do a release build of your solution.
When that's done, run ExportLogic, which creates a Logic Packages folder in your solution's folder. Logic Packages will contain:
Server Side Logic folder - contains the files you need to put on the server for your system to run correctly, minus installation-specific config files
Client Side Application folder (if your system contains a client-side app) - contains the files needed to correctly run your system's client-side app, minus installation-specific config files
Copy the contents of Server Side Logic to your server, then create an Installation folder inside the Configuration folder and put your installation-specific config files in it.
If your system has a database, execute the portion of Configuration\Database Updates.sql that has not already been executed against your live database.
Finally, for each web application folder you copied to the server, create an IIS web site or virtual directory pointing to it.
If you're interested in automating some/all of these steps, there are APIs within EWL that may help.

Prevent delete user generated content on visual studio 2010 publish

I have an application that stores images uploaded by user. Those images goes to content/images/upload. Problem is that if i published without the skip extra files on destination, all user uploaded content gets deleted. Im pretty sure im doing it wrongly, which would be the best approach for this situation ?
im worried about losing user generated content this way misconfiguring an option in publish.
One approach I've used is to move the physical path of the "upload" older outside the application folder structure. I'd use an IIS virtual directory to mount the folder to the application. For example, if the folder structure currently looks like this:
c:\inetpub\
wwwroot\
content\
images\
upload\
You might change it to this:
c:\inetpub
upload\ <-- must be manually created on the web server
wwwroot\
content\
images\
You'd remove the upload folder from the web application in Visual Studio. Log into the webserver and create the folder under inetpub (could go anywhere, really). Then go into IIS manager and create a virtual directory called upload that points to the c:\inetpub\upload folder.
The upload folder is no longer part of the Visual Studio project so the "publish" feature won't touch it.

Categories