在远程服务器中创建文件夹时出错

发布于 2024-11-18 20:57:51 字数 648 浏览 2 评论 0原文

您好,我有一个编写的代码,用于在 .net 的远程服务器中写入文件。当我将输出路径保留为本地驱动器时 - 代码工作正常并创建文件夹和文本文件。但是当我指向远程服务器时,出现以下错误:

System.UnauthorizedAccessException: Access to the path '\\ServerName\FolderTest\FolderTest1\AB.txt' is denied.
 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
 at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
 at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
 at ...

如果您需要其他信息,请告诉我

Hi I have a written for code for writing a file in the remote server in .net. When I keep output path as local drive - the code works fine and creates folders and text files. But when I point to a remote server, I get below error:

System.UnauthorizedAccessException: Access to the path '\\ServerName\FolderTest\FolderTest1\AB.txt' is denied.
 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
 at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
 at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
 at ...

If you need additional information let me know

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

青衫负雪 2024-11-25 20:57:51

您在什么环境中执行代码? Winforms、Web 表单还是 win 服务?
对于所有这些情况,有不同的方法可以解决此问题:

  • WinForms - 默认情况下,您的代码在您的凭据下执行,因此您的帐户必须具有远程服务器上 creatinf 文件夹的权限。
  • WebForms - 那么您的代码默认在本地 IIS 用户下执行,或者如果您使用模拟,则在您的帐户下执行,因此该帐户必须具有远程服务器上 creatinf 文件夹的权限。
  • 赢得服务 - 然后您的代码在本地服务、本地计算机、网络服务或该服务的某个用户下执行(查看此处了解详细信息),因此此帐户必须拥有远程服务器上 creatinf 文件夹的权限。

In which environment do you execute your code? Winforms, web forms or win services?
For all this cases, there are different wways to solve this issue:

  • WinForms - then your code is executes under your credentials by default, so your account must have the permissions for the creatinf folder on a remote server.
  • WebForms - then your code is executes under local IIS user by default, or under your account, if you use impersonation, so this accounts must have the permissions for the creatinf folder on a remote server.
  • Win services - then your code is executes either under local service, local machine, network service or some user for this service (look here for more info), so this accounts must have the permissions for the creatinf folder on a remote server.
安穩 2024-11-25 20:57:51

您可能需要为要保存文件的文件夹的正确用户设置权限。
这篇文章可能会为您提供答案:

链接 - System.UnauthorizedAccessException

You probably need to set the permisions to the right user on the folder where you want to save the file.
This post might have the answer for you:

Link - System.UnauthorizedAccessException

苦笑流年记忆 2024-11-25 20:57:51

代码现在可以正常工作了。问题是访问权限。我的代码写入该文件夹的凭据未添加到文件夹安全选项卡中。添加后就可以了。它起作用了。谢谢@James Deville、@VMAtm 和@Razvan Panda :)

The code worked properly now. The issue was the access permission. The credential with my code wrote to the folder was not added to the folder security tab. After adding to it. It worked. Thanks @James Deville, @VMAtm and @Razvan Panda :)

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