2010-06-08 43 views
2

当试图执行一个.NET-App时,它会抛出一个“PolicyException”,因为“只允许一个组”。 该工具应列出现有设置,并允许删除选定的设置。 使用卡斯波列表没有帮助,这是残酷的。是否存在命令行工具CASPOL.exe的替代品?

我见过有一个简单的gui-frontend,它允许定义新的设置,但它不允许列出或删除现有的设置。

卡斯波尔是一个噩梦,难怪任何人使用它的选择。在.NET 1.1中,Microsoft提供了一个配置实用程序,但对于.NET 2.0,我什么也没找到。

回答

1

还有一个配置小程序 2.0,以为它配备了2.0 SDK。如果你安装了它,它应该在Admin Tools并且被称为“Microsoft .NET Framework 2.0配置”。

0

该实用程序是.Net 2.0中的SDK的一部分。确保已安装。另外,你可能有兴趣知道.Net 3.5 sp1,后来用CAS去掉了一些痛点。

+0

谢谢,它的工作原理!该工具是“Mscorcfg.msc”,并与SDK一起安装(tx用于超链接)。 我发现它: C:\ Program Files \ Microsoft Visual Studio 8 \ SDK \ v2.0 \ Bin 无论如何,这是复杂的方式,但我重置所有设置后,PolicyException不见了,只设置需要的新。 – tantran 2010-06-08 16:40:07

1

你可以做你自己的工具(GUI或命令行)这一段代码:

static void SetPermission(string target) { 
    try { 
     // Find the machine policy level 
     PolicyLevel machinePolicyLevel = null; 
     System.Collections.IEnumerator policyHierarchy = SecurityManager.PolicyHierarchy(); 

     while (policyHierarchy.MoveNext()) { 
      PolicyLevel level = (PolicyLevel)policyHierarchy.Current; 
      if (level.Label == "Machine") { 
       machinePolicyLevel = level; 
       break; 
      } 
     } 


     if (machinePolicyLevel == null) { 
      throw new ApplicationException(
       "Could not find Machine Policy level. Code Access Security " + 
       "is not configured for this application." 
       ); 
     } 

     // Create a new FullTrust permission set 
     PermissionSet permissionSet = new NamedPermissionSet("FullTrust"); 

     IMembershipCondition membershipCondition = new UrlMembershipCondition(target); 

     // Create the code group 
     PolicyStatement policyStatement = new PolicyStatement(permissionSet); 
     CodeGroup codeGroup = new UnionCodeGroup(membershipCondition, policyStatement); 
     codeGroup.Description = "Custom code group created by PermSet utility."; 
     codeGroup.Name = "CustomCodeGroup-" + Guid.NewGuid().ToString(); 

     // Add the code group 
     machinePolicyLevel.RootCodeGroup.AddChild(codeGroup); 

     // Save changes 
     SecurityManager.SavePolicy(); 
    } 
    catch (Exception ex) { 
     Console.WriteLine(); 
     Console.WriteLine(ex.ToString()); 
     throw; 
    } 
} 
0

的Mscorcfg似乎并不已提供与以后的Visual Studio版本。我有2010年,但一直无法找到这个文件。