ImageResizer的DiskCache插件在本地运行良好,但是当我将WebRole部署到Azure时,部署分区太小,无法缓存大量文件。
具体来说,WebRole分区在一个小角色上大约是1GB。我想将缓存目录指向:
问题是WebRole所需的写权限。对于临时目录是否有简单的解决方法,还是需要一个PowerShell脚本来配置虚拟目录上的ACL并将其附加到WebRole的站点上?
在我走这条路之前,我想知道是否有人有合理的解决办法。
发布于 2013-06-07 03:26:58
在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发布于 2013-06-05 14:26:03
当DiskCache将文件服务委托给IIS以提高性能时,您将需要一个IIS虚拟文件夹。
DiskCache可以从任何虚拟文件夹缓存/服务文件,而不管其物理位置(尽管本地存储是最好的-延迟是不可接受的)。
临时文件夹不能工作,因为IIS和ASP.NET运行时用户帐户都需要读写访问,而且您肯定希望DiskCache是持久的。
这听起来确实需要为这个设置编写脚本。我认为很多人可以从这样的脚本中受益,如果你能在它完成后分享它的话。下面是如何编写IIS虚拟文件夹的脚本。
https://stackoverflow.com/questions/16941879
复制相似问题