Pau*_*ith 31 .net c# networking securityexception permissionset
从网络驱动器运行时我的.NET应用程序失败,即使同一个可执行文件从本地硬盘运行完全正常运行?
我尝试检查"完全信任",如下所示:
try
{
// Demand full trust permissions
PermissionSet fullTrust = new PermissionSet( PermissionState.Unrestricted );
fullTrust.Demand();
// Perform normal application logic
}
catch( SecurityException )
{
// Report that permissions were not full trust
MessageBox.Show( "This application requires full-trust security permissions to execute." );
}
Run Code Online (Sandbox Code Playgroud)
但是,这没有帮助,我的意思是应用程序启动并且永远不会输入catch块.但是,调试版本显示抛出的异常是由InheritanceDemand引起的SecurityException.有任何想法吗?
Dav*_*man 22
这确实与网络位置上的应用程序不太可信,然后在本地硬盘上这一事实有关(由于.NET框架的默认策略).
如果我没弄错,微软最终在.NET 3.5 SP1中纠正了这种烦恼(在许多开发者抱怨之后).
我谷歌了:.NET Framework 3.5 SP1允许从网络共享启动托管代码!
Ben*_*ein 11
您可能已经这样做了,但您可以使用CasPol.exe为指定的网络共享启用FullTrust.
例如
cd c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
CasPol.exe -m -ag 1.2 -url file:///N:/your/network/path/* FullTrust
Run Code Online (Sandbox Code Playgroud)
更多信息在这里.