Win 7请求获得类型'System.Security.Permissions.SecurityPermission的权限失败

时间:2011-04-06 19:57:23

标签: asp.net security windows-7 permission-denied

我有一个dll,它从用asp.net编写的Intranet Web应用程序访问本地计算机上的扫描程序。使用caspol在本地计算机上给予dll完全信任。在Win XP上一切正常,但在Win 7上没有。

代码是:

            PermissionSet ps = new PermissionSet(PermissionState.Unrestricted);
        ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.AllFlags));
        ps.Assert();


wiaDevMgr = new DeviceManager();
            foreach (DeviceInfo di in wiaDevMgr.DeviceInfos) {

对DeviceInfos的请求会引发以下错误:

Exception: Acquire from WIA failed Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

我已经使用caspol检查了实际权限 - 相关区域的条目是:

   1.2.  Zone - Intranet: FullTrust
  1.2.1.  All code: Same site Web
  1.2.2.  All code: Same directory FileIO - 'Read, PathDiscovery'
  1.2.3.  Url - http://srvr/tpc/pictureConverter.dll: FullTrust
  1.2.4.  Url - http://srvr/tpc/printUniformities.dll: FullTrust
  1.2.5.  Url - http://srvr/tpc/WiaOneScan.dll: FullTrust
  1.2.6.  Url - http://srvr/tpc/DocPrint.dll: FullTrust
  1.2.7.  Url - http://srvr/tpc/FileAdmin.dll: FullTrust
  1.2.8.  Url - http://srvr/tpc/Interop.ImageMagickObject.dll: FullTrust
  1.2.9.  Url - http://srvr/tpc/Interop.WIALib.dll: FullTrust

相关dll的位置是WiaOneScan.dll

感谢任何想法。

1 个答案:

答案 0 :(得分:1)

终于解决了。使用PermCalc.exe获取dll所需权限的列表。


            PermissionSet ps = new PermissionSet(PermissionState.Unrestricted);
            ReflectionPermission rp = new ReflectionPermission(PermissionState.Unrestricted);
            rp.Flags = ReflectionPermissionFlag.AllFlags;
            ps.AddPermission(rp);

            SecurityPermission sp = new SecurityPermission(PermissionState.Unrestricted);
            sp.Flags = SecurityPermissionFlag.AllFlags;
            ps.AddPermission(sp);

            KeyContainerPermission kc = new KeyContainerPermission(KeyContainerPermissionFlags.AllFlags);
            ps.AddPermission(kc);
            ps.Assert();