LicenseContext.GetSavedLicenseKey 需要 FileIOPermission

当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/p/2250002.html