Azure Approach and Sites

My Azure Web Role should be able to delete temporary local files stored in a subfolder of App_Data. I want to use ICACLS in an Azure-priority startup task to allow IIS to do this as follows:

ICACLS App_Data / grant "IIS_IUSRS": (OI) (CI) F

However, my launch task runs in:

E: \ approot \ Bin

While the root folder on which the web application actually ends and runs, is as follows:

E: \ sitesroot \ 0

I don’t want to hardcode this path if Microsoft changes this. Is there a way to get this path from a startup task, or can I rely on this destination?

To test this in ASPX, I add:

Label1.Text = "MapPath: " + Server.MapPath("~/");
Label2.Text = "RoleRoot: " + Environment.GetEnvironmentVariable("RoleRoot");

When I run this on a deployed instance, I get:

MapPath: E: \ sitesroot \ 0 \ RoleRoot:

. RoleRoot .

, Server.MapPath( "~/" ); ?

+3
4

, , , - () -.

+1

? , sitesroot, , , E:\ F: \, , , .

, :

xcopy "../../sitesroot/0/bin" "../../sitesroot/1/bin" /y /i /S
xcopy "../../sitesroot/0/bin" "../../sitesroot/2/bin" /y /i /S
xcopy "../../sitesroot/0/bin" "../../sitesroot/3/bin" /y /i /S
xcopy "../../sitesroot/0/bin" "../../sitesroot/4/bin" /y /i /S
xcopy "../../sitesroot/0/bin" "../../sitesroot/5/bin" /y /i /S
+3

icacls Powershell script, Powershell - IIS .

, Powershell script . CMD BAT , Powershell script.

CMD:

PowerShell -ExecutionPolicy Unrestricted .\Setup.ps1 >> %TEMP%\Setup-DebugLog.txt 2>&1
exit /B 0

Powershell script Setup-DebugLog.txt. , CMD OK Windows Azure, Azure , script .

Powershell script, App_Data:

Import-Module WebAdministration
cd IIS:\Sites
$dir = Get-ChildItem
$timeout = 0
while ($dir -eq $NULL -and $timeout -lt 11)
{
    "IIS Site not ready. Waiting for 2 seconds..."
    [System.Threading.Thread]::Sleep(2000)
    $timeout++
    $dir = Get-ChildItem
}

if ($dir -eq $NULL)
{
    "IIS Site still not ready. Aborting."
}
else
{
    "IIS site ready."
    Set-Location $dir.physicalPath
    "Location is $($dir.physicalPath)"
    $acl = (Get-Item App_Data).GetAccessControl("Access")
    $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Network Service", "Modify, Write", "ContainerInherit, ObjectInherit", "None", "Allow")
    $acl.AddAccessRule($rule)
    Set-Acl App_Data $acl
    "Permission added."
}

WebAdministration, Powershell IIS. -. . , - IIS. , . , -, - , 2 , . 20 , . - , , ACL App_Data FileSystemAccessRule. , . , script , IIS 1 . -, script , .

, XML, ServiceDefinition.csdef:

<Startup>
  <Task commandLine="Setup.cmd" executionContext="elevated" taskType="background" />
</Startup>

Setup.cmd Setup.ps1 -. , -, , commandLine Task "Subfolder\Setup.cmd", Powershell CMD:

PowerShell -ExecutionPolicy Unrestricted .\Subfolder\Setup.ps1 >> %TEMP%\Setup-DebugLog.txt 2>&1

Also note that there are some differences in calling the Powershell script between Powershell v1 and v2. If I remember correctly, Windows 2008 on Windows Azure launches Powershell v1, and Windows 2008 R2 and later Powershell v2. So, if you are using Windows 2008 on Azure, you will need to change the line that calls the Powershell script, as there is some difference in setting the execution policy.

+3
source

There are environment variables called% ROLEROOT% that get the path to your application.

string appRoot = Environment.GetEnvironmentVariable("RoleRoot");

appRoot = Path.Combine(appRoot + @"\", @"approot\");

Read more about it here .

+2
source

All Articles