从映射驱动器或共享文件夹运行 .NET 程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/359978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run a .NET program from a mapped drive or shared folder
提问by Rick
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.
我编写了一个 C# Windows 窗体应用程序,将一台机器上远程文件夹中的文件和文件夹(“源”文件夹是映射驱动器 - “Z:\folder”)与另一台机器上的另一个远程文件夹(“目标”文件夹是共享文件夹的 UNC 路径 - “\\计算机名\共享文件夹”)。我对这两个文件夹都有完全权限。当我在本地机器上运行该程序时,它工作正常,但是当我尝试从源文件夹中运行它时,它会因安全异常而失败。
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?
调用目标文件夹的 DirectoryInfo 构造函数时发生故障(即 DirectoryInfo(@"\\computername\sharedfolder")。我认为问题是因为我从映射驱动器运行程序。任何解决方法?
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.
具体的例外是:请求类型为“System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的权限失败。
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.
好的,我将我的应用程序安装到 Visual Studio 2008(之前在 2005 年编码),针对 .NET 3.5 框架,编译并再次尝试。
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.
我用 .NET 3.5 试过了,没有用,然后我注意到你说的是 3.5 SP1。肯定需要该服务包。
Problem solved. Thank you.
问题解决了。谢谢你。
采纳答案by Jon Galloway
.NET 3.5 SP1 allows running applications off a network share. Previous versions did not allow it.
.NET 3.5 SP1 允许在网络共享之外运行应用程序。以前的版本不允许。
回答by Rob Prouse
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.
您需要为应用程序启用 FullTrust 权限。在网络共享上运行的 .NET 应用程序被授予本地 Intranet 安全权限,因此在沙箱中运行。
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.
如上所述,.NET 3.5 删除了这种行为。