从映射驱动器或共享文件夹运行 .NET 程序

发布于 2024-07-09 12:01:15 字数 774 浏览 3 评论 0原文

我编写了一个 C# Windows 窗体应用程序,用于将一台计算机上的远程文件夹(“源”文件夹是映射驱动器 -“Z:\folder”)中的文件和文件夹与另一台计算机上的另一个远程文件夹(“目标”)合并文件夹是共享文件夹的 UNC 路径 - “\\computername\sharedfolder”)。 我对这两个文件夹都有完全权限。 当我在本地计算机上运行该程序时,它工作正常,但是当我尝试从源文件夹中运行它时,它会失败并出现安全异常。

调用目标文件夹的 DirectoryInfo 构造函数(即 DirectoryInfo(@"\\computername\sharedfolder") 时发生故障。我认为问题是因为我从映射驱动器运行程序。有任何解决方法吗?


具体的例外是: 请求“System.Security.Permissions.FileIOPermission,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”类型的权限失败。


更新

好的,我将我的应用程序放入 Visual Studio 2008(之前是在 2005 年编写的),针对 .NET 3.5 框架,进行编译并再次尝试。

我得到了完全相同的错误。


更新 - 解决方案

我用.NET 3.5尝试过,但没有成功,然后我注意到你说的是3.5 SP1。 肯定需要该服务包。

问题解决了。 谢谢。

I have written a C# Windows Forms application to merge the files and folders from a remote folder on one machine ("source" folder is a mapped drive - "Z:\folder") with another remote folder on a different machine ("destination" folder is a UNC path to a shared folder - "\\computername\sharedfolder"). I have Full permissions to both folders. When I run the program on my local machine, it works fine, but when I try to run it from from within the source folder it fails with a security exception.

The failure occurs when calling the DirectoryInfo constructor for the destination folder (i.e., DirectoryInfo(@"\\computername\sharedfolder"). I assume the problem is because I am running the program from a mapped drive. Any workarounds?


The specific exception is:
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.


UPDATE

okay, I got my application into Visual Studio 2008 (it was previously coded in 2005), targeted the .NET 3.5 framework, compiled and tried again.

I got the exact same error.


UPDATE - RESOLUTION

I tried it with .NET 3.5, and it didn't work, then I noticed that you said 3.5 SP1. The service pack is definately needed.

Problem solved. Thank you.

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

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

发布评论

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

评论(2

轻拂→两袖风尘 2024-07-16 12:01:15

您需要为应用程序启用 FullTrust 权限。 在网络共享上运行的 .NET 应用程序被授予本地 Intranet 安全权限,因此可以在沙箱中运行。

这是我为我们的一个在网络外运行的测试应用程序编写的批处理文件。 只需稍加修改,它就可以让您启动并运行。

@ECHO OFF
SET CASPOL=%windir%\Microsoft.NET\Framework\v2.0.50727\CasPol.exe
CLS

%CASPOL% -pp off
%CASPOL% -m -ag 1.2 -url file://server/directory/* FullTrust

如上所述,.NET 3.5 删除了此行为。

You need to enable FullTrust permissions for the application. .NET applications that run on a network share are given Local Intranet security permissions and thus run in a sandbox.

Here is a batch file that I wrote for one of our testing apps that runs off the network. It should get you up and running with minor modifications.

@ECHO OFF
SET CASPOL=%windir%\Microsoft.NET\Framework\v2.0.50727\CasPol.exe
CLS

%CASPOL% -pp off
%CASPOL% -m -ag 1.2 -url file://server/directory/* FullTrust

As stated above, .NET 3.5 removes this behaviour.

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