写入Azure localStorage错误"访问路径' C:\ Resources \ directory \ ....'被拒绝

时间:2013-09-18 21:36:45

标签: c# powershell azure-storage azure-web-roles

当我尝试将文件从azure blob下载到azure localstorage时,它向我显示一条消息“拒绝访问路径'C:\ Resources \ directory ....'被拒绝。 As解决方法我添加了一个带有power shell命令的statup任务来启用权限。但是之后发现我的web角色需要更多时间来启动并最终启动。但是当我尝试写入时,我仍然收到访问被拒绝错误消息它.感谢您解决此问题的建议

我还尝试将我的powershell脚本的编码更改为Unicode(没有签名的UTF-8) - 代码页65001.如上所述here。但没有运气。请帮忙

这是我的StartUp.Cmd文件

    @echo off


REM   Attempt to set the execution policy by using PowerShell version 2.0 syntax.
PowerShell -Version 2.0 -ExecutionPolicy Unrestricted .\fixfolderaccess.ps1 >> "%TEMP%\StartupLog.txt" 2>&1

IF %ERRORLEVEL% EQU -393216 (
   REM   PowerShell version 2.0 isn't available. Set the execution policy by using the PowerShell version 1.0 calling method.

   PowerShell -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1
   PowerShell .\fixfolderaccess.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
)

这是我的powershell脚本 - fixpermission.ps1。

Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime

while (!$?)
{
    echo "Failed, retrying after five seconds..."
    sleep 5

    Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime
}

echo "Added WA snapin."

$localresource = Get-LocalResource "Resources"
$folder = $localresource.RootPath

$acl = Get-Acl $folder

$rule1 = New-Object System.Security.AccessControl.FileSystemAccessRule(
  "Administrators", "FullControl", "ContainerInherit, ObjectInherit", 
  "None", "Allow")
$rule2 = New-Object System.Security.AccessControl.FileSystemAccessRule(
  "Everyone", "FullControl", "ContainerInherit, ObjectInherit", 
  "None", "Allow")

$acl.AddAccessRule($rule1)
$acl.AddAccessRule($rule2)

Set-Acl $folder $acl

echo "Done changing ACLs."

我的.cmd文件和fixpermission.ps1文件都在web项目目录中,并且set property copy always = true。

如果我在本地计算机上手动运行startup.cmd,则会出现以下错误

.\fixfolderaccess.ps1 : The term '.\fixfolderaccess.ps1' is not recognized as t
he name of a cmdlet, function, script file, or operable program. Check the spel
ling of the name, or if a path was included, verify that the path is correct an
d try again.
At line:1 char:22
+ .\fixfolderaccess.ps1 <<<< 
    + CategoryInfo          : ObjectNotFound: (.\fixfolderaccess.ps1:String) [ 
   ], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

当我远程访问我的webrole时,我可以看到下面粘贴的错误消息。

C a n n o t   s t a r t   W i n d o w s   P o w e r S h e l l   v e r s i o n   2 . 0   b e c a u s e   i t   i s   n o t   c o r r e c t l y   i n s t a l l e d . 

 Add-PSSnapin : Cannot load Windows PowerShell snap-in Microsoft.WindowsAzure.Se
rviceRuntime because of the following error: The Windows PowerShell snap-in mod
ule F:\plugins\RemoteAccess\Microsoft.WindowsAzure.ServiceRuntime.Commands.dll 
does not have required Windows PowerShell snap-in strong name Microsoft.Windows
Azure.ServiceRuntime.Commands, Version=1.0.0.0, Culture=neutral, PublicKeyToken
=31bf3856ad364e35.
At F:\approot\bin\fixfolderaccess.ps1:1 char:13
+ Add-PSSnapin  <<<< Microsoft.WindowsAzure.ServiceRuntime
Failed, retrying after five seconds...
out-lineoutput : The OS handle's position is not what FileStream expected. Do n
ot use a handle simultaneously in one FileStream and in Win32 code or another F
ileStream. This may cause data loss.

现在我实际上登录了我的azure webrole并手动执行了powershell脚本,我收到了以下错误

Add-PSSnapin:由于以下内容,无法加载Windows PowerShell管理单元Microsoft.WindowsAzure.ServiceRuntime ror:Windows PowerShell管理单元模块E:\ plugins \ RemoteAccess \ Microsoft.WindowsAzure.ServiceRuntime.Commands.dll oes不需要Windows PowerShell管理单元强名称Microsoft.WindowsAzure.ServiceRuntime.Commands,Version = 1 0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35。 在E:\ sitesroot \ 0 \ bin \ fixfolderaccess.ps1:8 char:17 + Add-PSSnapin&lt;&lt;&lt;&lt; Microsoft.WindowsAzure.ServiceRuntime

问题

我最近升级到windows azure tools ver 2.1和VisualStudio2012.But我的项目文件目标仍指向Framework 4.0。你认为我是否将所有项目文件的目标框架升级到.Net4.5并将每个dll升级到。净4.5和所有这些麻烦可能会消失?

是否有直接的方式来授予对azure本地存储的所需写入权限?

0 个答案:

没有答案