从网络共享运行"部分受信任的" .NET程序集
当我尝试从网络共享(映射到驱动器)运行.NET程序集(boo.exe)时,它失败了,因为它仅部分受信任:
Unhandled Exception: System.Security.SecurityException: That assembly does not allow partially trusted callers. at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) at BooCommandLine..ctor() at Program..ctor() at ProgramModule.Main(String[] argv) The action that failed was: LinkDemand The assembly or AppDomain that failed was: boo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=32c39770e9a21a67 The Zone of the assembly that failed was: Intranet The Url of the assembly that failed was: file:///H:/boo-svn/bin/boo.exe
根据博客文章的说明,我向.NET配置中添加了一个策略,该策略完全信任所有以file:/// H:/ *'作为其URL的程序集。我通过在.NET Configuration中的"评估程序集"工具中输入URL
file:/// H:/ boo-svn / bin / boo.exe`并注意到boo.exe具有Unrestricted权限(它没有之前没有政策)。
即使获得许可,boo.exe
也不会运行。我仍然收到相同的错误消息。
我该怎么做才能调试此问题?是否有另一种方法可以从网络共享中运行"部分受信任的"程序集,而不必为我要运行的每个程序集更改某些内容?
解决方案
回答
使用.NET 3.5 SP1,从UNC共享运行的.NET程序集具有完全权限。
有关变通办法和讨论,请参见Brad Abrams的"允许从网络共享运行.exe",最后,后续的.NET 3.5 SP1允许从网络共享启动托管代码。
回答
我认为我们想将AllowPartiallyTrustedCallers属性添加到程序集。该错误消息表明正在完全调用boo.exe程序集中的某些内容,并且boo.exe没有允许它的此属性。
回答
看一下" caspol.exe"程序(.NET运行时提供)。我们将必须在尝试从中运行应用程序的计算机上执行此操作。我无法"标记"和组装(可能只是我自己)。但是,使用caspol并为我的应用LocalIntranet_Zone设置适当的权限,可以解决类似的问题。
我听说过(但尚未尝试过),. NET 3.5 sp1删除了此严格的安全要求(默认情况下不允许.NET程序集驻留在共享上)。
回答
我按照Johnny Hughes的博客文章"通过网络共享运行.Net应用程序"中的说明使用caspol
解决了此问题:
caspol -addgroup 1.2 -url file:///H:/* FullTrust
看来用于管理策略的.NET配置GUI根本不起作用。