当尝试执行.NET应用程序时,它抛出一个"PolicyException",因为“只允许一个组”。该工具应列出现有设置,并允许删除所选设置。使用caspol列表是没有帮助的,它是残酷的。
我已经看到有一个简单的gui-frontend,它允许定义新的设置,但不允许列出或删除现有的设置。
卡斯波尔是一场噩梦,难怪会有人选择使用它。对于.NET 1.1,微软提供了一个配置实用程序,但是对于.NET 2.0,我什么都没有找到。
发布于 2010-06-08 22:46:00
还有一个针对2.0的配置Applet,我想它是随2.0 SDK一起提供的。如果你安装了它,它应该在Admin Tools中,并被称为“微软.NET Framework2.0配置”。
发布于 2010-06-08 22:48:41
您可以使用下面这段代码来创建自己的工具(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-08 22:48:13
该实用程序是.Net 2.0中SDK的一部分。请确保已安装该程序。
此外,您可能有兴趣知道,CAS 3.5 sp1和更高版本消除了.Net的一些痛点。
https://stackoverflow.com/questions/2998337
复制相似问题