Unhandled Exception: System.Security.SecurityException

背景:我的应用程序可以运行用户指定的assembly中的代码,给个路径url就行了。

出事了: 用户报了一个bug,说当指定assembly的路径是本地路径,运行没问题,如果是非本地路径就会有一个错误提示。

Unhandled Exception: System.Security.SecurityException: Request for the permiss
on of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0
0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlM
rk& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessPermission.Demand()
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access,
nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions
ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.StreamWriter.CreateFile(String path, Boolean append)
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encodi
g, Int32 bufferSize)
   at System.IO.StreamWriter..ctor(String path)
   at COD_ITB.App_main_process.main()
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The first permission that failed was:
<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Ver
ion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

 

解决:当你运行一个非本地assembly时,需要对code access security进行必要的设置。

>caspol -m -ag 1 -url http://www.cnblogs.com/Kratos/admin/file:z:\* FullTrust

it will grant fulltrust to z:\ assemblies.

转载于:https://www.cnblogs.com/Kratos/archive/2010/01/21/1653096.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值