Directory.Move() 在调试模式下工作,但在部署时不工作

发布于 2024-09-15 11:23:22 字数 489 浏览 5 评论 0原文

我有一个网络应用程序,它可以对别名目录进行读/写/执行访问。当我在 Visual Studio 中处于调试模式时,以下语句有效:

Directory.Move("\\\\localhost\\Alias\\oldDirectory","\\\\localhost\\Alias\\newDirectory");

最终结果是,oldDirectory 现在是别名目录中的 newDirectory

但是,当我在预生产中测试此代码时,别名目录中有 oldDirectorynewDirectoryDirectory.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九局 2024-09-22 11:23:22

这很可能是权限问题。

执行此命令的用户帐户可能在别名目录中具有创建/写入权限,但没有删除权限。我会检查程序正在执行的用户帐户是否具有删除/删除子文件夹和文件权限。

编辑:

为了测试这个理论,我将暂时授予用户组对该文件夹的完全控制权,看看问题是否消失。

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.

走过海棠暮 2024-09-22 11:23:22
  • 确保该文件夹未处于写保护状态,并且在您尝试移动该文件夹时没有进程正在访问任何文件。

  • 还要检查您是否向正确的用户授予了安全权限,方法是验证应用程序池在哪个用户帐户下运行。

  • 您可能还需要考虑在本地 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)

[旋木] 2024-09-22 11:23:22

我相信,我没有使用 Directory (静态的),而是使用 DirectoryInfo 解决了我的问题。我认为问题的核心在于 DirectoryDirectoryInfo 实例执行更多的安全检查。我仍然不清楚为什么会这样,但它似乎有效。

I believe that, instead of using Directory (which is static) I used DirectoryInfo which solved my problem. I think that the heart of the issue was that Directory does more security checks than an instance of DirectoryInfo does. I'm still unclear why this is, but it seemed to work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文