![](/img/trans.png)
[英]How can I access a file that's part of the deployment in an Azure Webrole
[英]How can I properly set the cache directory for ImageResizer on an Azure WebRole?
ImageResizer的DiskCache插件在本地工作正常,但是当我将WebRole部署到Azure时,部署分区太小而无法缓存大量文件。
具体来说,WebRole分区在一个小角色上约为1GB。 我想将缓存目录指向:
问题是WebRole所需的写权限。 是否有临时目录的简单解决方法,或者我是否需要PowerShell脚本来配置虚拟目录上的ACL并将其附加到WebRole的站点?
在我走这条路之前,我想知道是否有人有合理的解决方法。
在ServiceDefinition.csdef中:
<Task commandLine="makevdir.cmd" executionContext="elevated" taskType="background" />
Makevdir.cmd:
PowerShell -ExecutionPolicy Unrestricted .\makevdir.ps1 >> "%RoleRoot%\makevdir.txt" 2>&1
EXIT /B %errorlevel%
Makevdir.ps1:
# Make Virtual Directory for ImageResizer DiskCache plugin (/imagecache)
Write-Host "makevdir.ps1 starting"
# $ImageCacheDir = $env:temp + "\imagecache"
#
# The TEMP paths are quota limited to ~100MB, so use a hard coded path:
$ImageCacheDir = "C:\Resources\AspNetTemp\imagecache"
Write-Host "ImageCacheDir = $ImageCacheDir"
md -Path $ImageCacheDir
# Set the ACL to allow IIS access to the new directory
$acl = Get-Acl $ImageCacheDir
$identity = "IIS_IUSRS"
$fileSystemRights = "Modify"
$inheritanceFlags = "ContainerInherit, ObjectInherit"
$propagationFlags = "None"
$accessControlType = "Allow"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($identity, $fileSystemRights, $inheritanceFlags, $propagationFlags, $accessControlType)
$acl.SetAccessRule($rule)
Set-Acl $ImageCacheDir $acl
# Get the AppName by appending _Web/ to the RoleInstanceID environmental variable
$AppName = $env:RoleInstanceID + "_Web/"
Write-Host "AppName = $AppName"
# Retry creating the virtual directory every five seconds for a maximum of 20 tries
$tries = 0
& $Env:WinDir\system32\inetsrv\appcmd.exe add vdir /app.name:$AppName /path:/imagecache /physicalpath:$ImageCacheDir
while (!$? -and $tries -lt 20) {
$tries++
sleep 5
& $Env:WinDir\system32\inetsrv\appcmd.exe add vdir /app.name:$AppName /path:/imagecache /physicalpath:$ImageCacheDir
}
Write-Host "makevdir.ps1 exiting"
Exit
由于DiskCache将文件服务委托给IIS以提高性能,因此您需要一个IIS虚拟文件夹。
DiskCache可以从任何虚拟文件夹缓存/提供文件,无论其物理位置如何(尽管本地存储最佳 - 延迟是不可接受的)。
临时文件夹不起作用,因为IIS和ASP.NET运行时用户帐户都需要读/写访问权限,并且您肯定希望DiskCache是持久的。
听起来你需要为此设置脚本。 我想很多人都可以从这样的脚本中受益,如果你可以在完成后分享它。 以下是如何编写IIS虚拟文件夹的脚本 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.