2

当尝试执行 .NET-App 时,它会抛出“PolicyException”,因为“只允许一个组”。该工具应列出现有设置,并允许删除选定的设置。使用 caspol 列出没有帮助,很残忍。

我看到有一个简单的 gui 前端,它允许定义新设置,但它不允许列出或删除现有设置。

Caspol 是一场噩梦,难怪有人选择使用它。对于 .NET 1.1,Microsoft 提供了一个配置实用程序,但对于 .NET 2.0,我什么也没找到。

4

4 回答 4

1

还有一个用于 2.0 的配置小程序,认为它与 2.0 SDK 一起提供。如果你安装了它,它应该在“Microsoft .NET Framework 2.0 Configuration”中Admin Tools并被称为“Microsoft .NET Framework 2.0 Configuration”。

于 2010-06-08T14:45:59.793 回答
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;
    }
}
于 2010-06-08T14:48:40.813 回答
0

更高版本的 Visual Studio 似乎没有提供 MsCorCfg。我有 2010,但无法找到此文件。

于 2010-07-15T19:33:59.053 回答
0

该实用程序是.Net 2.0中SDK的一部分。确保已安装。

此外,您可能有兴趣知道 .Net 3.5 sp1 以及后来消除了 CAS 的一些痛点。

于 2010-06-08T14:48:12.807 回答