LicenseContext.GetSavedLicenseKey 需要 FileIOPermission

本文深入探讨了在ASP.NET应用的MediumTrust环境中,使用Context.GetSavedLicenseKey方法时遇到的权限限制问题。重点介绍了如何在没有EntryAssembly的情况下,通过AppDomain.CurrentDomain.GetAssemblies()来获取包含指定资源(如.licenses文件)的assembly,从而解决SecurityException问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当ASP.NET 运行于 Medium Trust 环境下,有两种情况:

Context.GetSavedLicenseKey(type, null), 会有SecurityException 抛出,提示需要FileIOPermission;

Context.GetSavedLicenseKey(type, assembly), 但assembly不为null时,可以正常使用。

 

怎样得到assembly, 大部分的时候都是通过Assembly.GetEntryAssembly() 获得。在ASP.NET环境下,Entry Assembly 一直是null.

怎么办?可以在AppDomain.CurrentDomain.GetAssemblies() 中搜索含有 xxx.licenses资源的assembly

 

有关于Medium Trust的描述可以参考:

 

Medium Trust Summary

The main constraints placed on medium trust Web applications are:

  • OleDbPermission is not available. This means you cannot use the ADO.NET managed OLE DB data provider to access databases. However, you can use the managed SQL Server provider to access SQL Server databases.
  • EventLogPermission is not available. This means you cannot access the Windows event log.
  • ReflectionPermission is not available. This means you cannot use reflection.
  • RegistryPermission is not available. This means you cannot access the registry.
  • WebPermission is restricted. This means your application can only communicate with an address or range of addresses that you define in the <trust> element.
  • FileIOPermission is restricted. This means you can only access files in your application's virtual directory hierarchy. Your application is granted Read, Write, Append, and PathDiscovery permissions for your application's virtual directory hierarchy.

You are also prevented from calling unmanaged code or from using Enterprise Services.

 

http://msdn.microsoft.com/en-us/library/ff648344.aspx

转载于:https://www.cnblogs.com/xixifusigao/archive/2011/11/15/2250002.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值