CodeConnectAccess Class
Assembly: mscorlib (in mscorlib.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Class CodeConnectAccess 'Usage Dim instance As CodeConnectAccess
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public class CodeConnectAccess
SerializableAttribute ComVisibleAttribute(true) public class CodeConnectAccess
Not applicable.
This class is used in conjunction with the NetCodeGroup class to control how executing code can connect back to the site it was downloaded from. These classes provide programmatic control of the WebPermission granted to executing code that controls what schemes and ports the code can use access its origin site. You can specify scheme and port pairs that are permitted based on the scheme in the URL where the code originates.
To create a CodeConnectAccess object based on the code's origin scheme, use the CreateOriginSchemeAccess method.
To create a CodeConnectAccess object that can use any scheme but is restricted by port, use the CreateAnySchemeAccess method.
The following code example creates a NetCodeGroup object and adds it to the User policy level.
public static void SetNetCodeGroupAccess() throws ApplicationException
{
final String userPolicyLevel = "User";
// Locate the User policy level.
PolicyLevel level = null;
System.Collections.IEnumerator ph =
System.Security.SecurityManager.PolicyHierarchy();
while (ph.MoveNext()) {
level = (PolicyLevel)ph.get_Current();
if (level.get_Label().Equals(userPolicyLevel)) {
break;
}
}
if (!(level.get_Label().Equals(userPolicyLevel))) {
throw new ApplicationException("Could not find User policy level.");
}
IMembershipCondition membership =
new UrlMembershipCondition("http://www.contoso.com/*");
NetCodeGroup codeGroup = new NetCodeGroup(membership);
// Delete default settings.
codeGroup.ResetConnectAccess();
// Create an object that represents access to the FTP scheme and
// default port.
CodeConnectAccess a1 =
new CodeConnectAccess(Uri.UriSchemeFtp,
CodeConnectAccess.DefaultPort);
// Create an object that represents access to the HTTPS scheme
// and default port.
CodeConnectAccess a2 = new CodeConnectAccess(Uri.UriSchemeHttps,
CodeConnectAccess.DefaultPort);
// Create an object that represents access to the origin scheme and port.
CodeConnectAccess a3 = CodeConnectAccess.CreateOriginSchemeAccess(
CodeConnectAccess.OriginPort);
// Add connection access objects to the NetCodeGroup object.
codeGroup.AddConnectAccess(Uri.UriSchemeHttp, a1);
codeGroup.AddConnectAccess(Uri.UriSchemeHttp, a2);
codeGroup.AddConnectAccess(Uri.UriSchemeHttp, a3);
// Provide name and description information for caspol.exe tool.
codeGroup.set_Name("ContosoHttpCodeGroup");
codeGroup.set_Description("Code originating from contoso.com can"
+ " connect back using the FTP or HTTPS.");
// Add the code group to the User policy's root node.
level.get_RootCodeGroup().AddChild(codeGroup);
// Save the changes to the policy level.
System.Security.SecurityManager.SavePolicy();
} //SetNetCodeGroupAccess
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.