Nas*_*sir 1 c# .net-4.0 caspol .net-security c#-4.0
从网络共享运行时,我的应用程序抛出以下异常:
该程序集不允许部分信任的调用者.
我的应用程序引用两个DLL文件:
我不确定它有哪些问题.
AllowPartiallyTrustedCallersAttribute:阅读它,但我没有任何DLL文件的源,所以我无法将属性添加到这些DLL文件.
CASPOL.EXE:使用一些变体添加我的网络共享,例如caspol -machine -addgroup 1. -url \\netserver\netshare\* LocalIntranet似乎没有任何影响.
我之前使用的是.NET 3.5,但是,它现在似乎与.net 4.0不兼容.任何人都可以建议如何绕过这个"部分受信任的来电者"检查?
谢谢.
Jef*_*tin 11
.NET 4.0已更改安全策略的默认规则.您需要App.config为此应用程序创建或修改该文件.
CASPOL现在,在.NET 4.0中默认忽略代码访问安全性(由配置).如果要启用它,则需要将以下内容添加到app.config文件中:
<configuration>
<runtime>
<!-- enables legacy CAS policy for this process -->
<NetFx40_LegacySecurityPolicy enabled="true" />
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
您可以使用LoadFrom以下配置项将.NET 4.0配置为使用完全受信任的方式处理来自网络的代码:
<configuration>
<runtime>
<!-- Treat assemblies from network locations as fully trusted. -->
<!-- Caution: Do not point this loaded gun at your foot. -->
<loadFromRemoteSources enabled="true" />
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10867 次 |
| 最近记录: |