Adding CodeGroups / Framework Version

M

Matt Theule

How do I programatically add a code group to a particular version of
the dotNet framework, or better yet, ALL versions fo the framework?

Using the code below, I can add a CodeGroup to the machine policy of a
computer to fully trust all assemblies from a particular website.

The problem arises in that I use VS 2002 to run the code below and I
have FW v1.0 *AND* FW v1.1 installed on my workstation. When the code
below runs, the code group is visible in the Configuration tool that
installed with FW 1.0. It is *NOT* visible in the Configuration 1.1
tool.

The aspx application that needs to access the assemblies that are
refrenced in the new code group is using FW 1.1, so the application
fails to run. If manually add the code group to the Configuration 1.1
tool, the application runs.

How can I register a code group with *ALL* the installed versions of
dotNet framework?

Thanks


public void AddCodeGroup{
PolicyLevel machinePolicyLevel = null;
System.Collections.IEnumerator ph = SecurityManager.PolicyHierarchy();
while( ph.MoveNext() )
{
PolicyLevel pl = (PolicyLevel)ph.Current;
if( pl.Label == "Machine" )
{
machinePolicyLevel = pl;
break;
}
}
PermissionSet permSet1 = new NamedPermissionSet("FullTrust");
IMembershipCondition membership1 =
new UrlMembershipCondition("http://scc---wsmattt02/*");
PolicyStatement policy1 = new PolicyStatement(permSet1);
CodeGroup codeGroup1 = new UnionCodeGroup(membership1, policy1);
codeGroup1.Name = "FullyTrustedCodeGroup";
machinePolicyLevel.RootCodeGroup.AddChild(codeGroup1);
SecurityManager.SavePolicy();
}
 
R

Robert Gruen [MSFT]

You are going to run into issues here since your assembly is compiled to
run against one specific version of the framework. Even if you have a 1.1
assembly that has a config file that lets it run against 1.0 the assembly
will be loaded into one version of the framework or another. So, the
policy changes you are making in code will only affect the loaded runtime.

What you can do, it generate an XML policy configuration (using code or
otherwise), and then import it into the various frameworks by calling the
different versions of caspol
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpconnewpermissions.asp) that are on the box. This of course will
entail you determine what versions of the framework are running on the box.

Thanks! Robert Gruen
Microsoft, VB.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top