Directory.Move() 在调试模式下工作,但在部署时不工作
我有一个网络应用程序,它可以对别名目录进行读/写/执行访问。当我在 Visual Studio 中处于调试模式时,以下语句有效:
Directory.Move("\\\\localhost\\Alias\\oldDirectory","\\\\localhost\\Alias\\newDirectory");
最终结果是,oldDirectory
现在是别名目录中的 newDirectory
。
但是,当我在预生产中测试此代码时,别名目录中有 oldDirectory
和 newDirectory
。 Directory.Move
现在的行为就好像它只是将 oldDirectory
复制到 newDirectory
。
为什么会发生这种情况?
I have a webapp which has read/write/execute access to an aliased directory. When I am in debug mode in Visual Studio, the following statement works:
Directory.Move("\\\\localhost\\Alias\\oldDirectory","\\\\localhost\\Alias\\newDirectory");
The net result is that, oldDirectory
is now newDirectory
in the aliased directory.
But, when I'm testing this code in pre-production, I have oldDirectory
and newDirectory
in the aliased directory. Directory.Move
is now behaving as if it is only copying oldDirectory
to newDirectory
.
Why is this happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这很可能是权限问题。
执行此命令的用户帐户可能在别名目录中具有创建/写入权限,但没有删除权限。我会检查程序正在执行的用户帐户是否具有删除/删除子文件夹和文件权限。
编辑:
为了测试这个理论,我将暂时授予用户组对该文件夹的完全控制权,看看问题是否消失。
This is most likely a permissions issue.
The user account that is executing this command probably has Create / Write permissions but not Delete permissions in the aliased directory. I would check whether the user account that the program is executing under has Delete / Delete Subfolders and Files permissions.
Edit:
To test this theory, I would temporarily grant the Users group Full Control over the folder to see if the problem goes away.
确保该文件夹未处于写保护状态,并且在您尝试移动该文件夹时没有进程正在访问任何文件。
还要检查您是否向正确的用户授予了安全权限,方法是验证应用程序池在哪个用户帐户下运行。
您可能还需要考虑在本地 IIS 上进行开发,以防止将来出现此类情况(我曾经经历过;不太好)
Make sure the folder is not under write-protection and no process is accessing any files at the moment you are trying to move the folder.
Also check whether you gave the security permissions to the correct user, by verifing under which user account the applicationpool is running.
You might also want to consider developing on a local IIS to prevent such situations in the future (I've been there; not nice)
我相信,我没有使用
Directory
(静态的),而是使用DirectoryInfo
解决了我的问题。我认为问题的核心在于Directory
比DirectoryInfo
实例执行更多的安全检查。我仍然不清楚为什么会这样,但它似乎有效。I believe that, instead of using
Directory
(which is static) I usedDirectoryInfo
which solved my problem. I think that the heart of the issue was thatDirectory
does more security checks than an instance ofDirectoryInfo
does. I'm still unclear why this is, but it seemed to work.