Export (0) Print
Expand All

CodeConnectAccess.CreateOriginSchemeAccess Method

Note: This method is new in the .NET Framework version 2.0.

Returns a CodeConnectAccess instance that represents access to the specified port using the code's scheme of origin.

Namespace: System.Security.Policy
Assembly: mscorlib (in mscorlib.dll)

public static CodeConnectAccess CreateOriginSchemeAccess (
	int allowPort
)
public static CodeConnectAccess CreateOriginSchemeAccess (
	int allowPort
)
public static function CreateOriginSchemeAccess (
	allowPort : int
) : CodeConnectAccess

Parameters

allowPort

The port represented by the returned instance.

Return Value

A CodeConnectAccess instance for the specified port.

Exception typeCondition

ArgumentOutOfRangeException

allowPort is less than 0.

-or-

allowPort is greater than 65,535.

The CodeConnectAccess instance returned by this method has the scheme value OriginScheme. The origin scheme is the scheme value from the URI where the code originated.

The following code example demonstrates using CodeConnectAccess objects to create a code group and adding the code group to a policy level.

public static void SetNetCodeGroupAccess()
{
    const 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.Current;
        if( level.Label == userPolicyLevel )
        {
            break;
        }
    }
    if (level.Label != 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.Name = "ContosoHttpCodeGroup";
    codeGroup.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.RootCodeGroup.AddChild(codeGroup);
    // Save the changes to the policy level.
    System.Security.SecurityManager.SavePolicy();
}

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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft