Azure and edit or delete deployed files from your website

by ingvar 21. December 2010 09:32

If you change the file permission on deployed files in the WebRole, you will be able to edit or delete those files from you website. This includes the web.config file!
Also if you write new files in the WebRole, you also need to change the file permission for those files.

My colleague at Composite Marcus Wendt found the code for changing the file permission here. Ill restate the code below. This code is not enough, you also need to edit the ServiceDefinition.csdef file. You need to add '<Runtime executionContext="elevated" />' to the ServiceDefinition.csdef file to give your WebRole rights to change file permissions:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AzureTest"
  <WebRole name="WebRole">
    <Runtime executionContext="elevated" />


And here is the code for changing the permission for a given file:

void ChangePermission(string filePath)
    SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);

    IdentityReference act = sid.Translate(typeof(NTAccount));

    FileSecurity sec = File.GetAccessControl(filePath);
    sec.AddAccessRule(new FileSystemAccessRule(act, FileSystemRights.FullControl,

    File.SetAccessControl(filePath, sec);


.NET | Azure | C#

Comments (2) -

Dalibor Czech Republic
1/7/2011 9:57:37 AM #

The problem with such approach is that after a VM gets recycled from any reason, it is rebooted from origial deployment file which doesn't contain file changes you had made. An app may get recycled at any time and you loose any changes you made on local FS.

ingvar Denmark
1/7/2011 10:06:20 AM #

@Dalibor You are correct! In the future I'll do a blob post on how to solve this issue, so stay tuned Smile

Pingbacks and trackbacks (1)+

About the author

Martin Ingvar Kofoed Jensen

Architect and Senior Developer at Composite on the open source project Composite C1 - C#/4.0, LINQ, Azure, Parallel and much more!

Follow me on Twitter

Read more about me here.

Read press and buzz about my work and me here.

Stack Overflow

Month List