Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

UrlIdentityPermission.Union Method

Creates a permission that is the union of the current permission and the specified permission.

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

public override IPermission Union (
	IPermission target
)
public IPermission Union (
	IPermission target
)
public override function Union (
	target : IPermission
) : IPermission

Parameters

target

A permission to combine with the current permission. It must be of the same type as the current permission.

Return Value

A new permission that represents the union of the current permission and the specified permission.
Exception typeCondition

ArgumentException

The target parameter is not a null reference (Nothing in Visual Basic) and is not of the same type as the current permission.

-or-

The Url property is not a valid URL.

-or-

The two permissions are not equal and one is not a subset of the other.

The result of a call to the Union method is a permission that represents access to the URL as represented by the current permission, as well as access to the URL as represented by the specified permission.

The UrlIdentityPermission class supports set operations IsSubsetOf, Intersect, and Union) only when the current permission is equal to the specified permission, or when one of the permissions uses the wildcard operator ("*") and one is a subset of the other.

The following code example shows the results of the use of the Union method, not how to use the method. This code is part of a larger example. The best use for this example is to build and execute the entire example, and view its output. For the complete example, refer to the UrlIdentityPermission class.

// Union creates a new permission that is the union of the current permission and
// the specified permission.
private bool UnionDemo()
{

    bool returnValue = true;

    string url1, url2;
    UrlIdentityPermission urlIdPerm1, urlIdPerm2;
    IPermission urlIdPerm3;

    UrlGenerator urlGen1 = new UrlGenerator();
    UrlGenerator urlGen2 = new UrlGenerator();

    urlGen1.ResetIndex();
    while (urlGen1.CreateUrl(out url1))
    {
        urlIdPerm1 = new UrlIdentityPermission(url1);

        Console.WriteLine("**********************************************************\n");
        urlGen2.ResetIndex();
        while (urlGen2.CreateUrl(out url2))
        {

            try
            {
                urlIdPerm2 = new UrlIdentityPermission(url2);

                string firstPermission = url1 == "" | url1 == null ? "null" : url1;
                string secondPermission = url2 == "" | url2 == null ? "null" : url2;
                urlIdPerm3 = (UrlIdentityPermission)urlIdPerm1.Union(urlIdPerm2);
                urlIdPerm3 = urlIdPerm1.Union(urlIdPerm2);

                if (urlIdPerm3 == null)
                {
                    Console.WriteLine("The union of " + firstPermission
                        + " and \n\t" + secondPermission + " is null.");
                }
                else
                {
                    Console.WriteLine("The union of " + firstPermission + " and \n\t"
                        + secondPermission +
                        " = \n\t" + ((UrlIdentityPermission)urlIdPerm3).Url.ToString());
                }
            }
            catch (Exception e)
            {   //Expected exception.
                Console.WriteLine("An exception was thrown for union :" + e.Message);
            }

        }

    }

    return returnValue;

}

// Union creates a new permission that is the union
// of the current permission and
// the specified permission.
private boolean UnionDemo()
{
    boolean returnValue = true;
    String url1[] = new String[1];
    String url2[] = new String[1];
    UrlIdentityPermission urlIdPerm1[] = new UrlIdentityPermission[1];
    UrlIdentityPermission urlIdPerm2[] = new UrlIdentityPermission[1];
    IPermission urlIdPerm3;
    UrlGenerator urlGen1 = new UrlGenerator();
    UrlGenerator urlGen2 = new UrlGenerator();

    urlGen1.ResetIndex();
    while (urlGen1.CreateUrl(urlIdPerm1, url1)) {
        if (urlIdPerm1 == null) {
            continue;
        }

        Console.WriteLine("******************************************" 
            + "****************\n");
        urlGen2.ResetIndex();
        while (urlGen2.CreateUrl(urlIdPerm2, url2)) {
            try {
                if (urlIdPerm2 == null) {
                    continue;
                }
                String firstPermission = (url1[0] == "" 
                    || url1[0] == null) ? "null" : url1[0];
                String secondPermission = (url2[0] == "" 
                    || url2[0] == null) ? "null" : url2[0];

                urlIdPerm3 = ((UrlIdentityPermission)(urlIdPerm1[0].
                Union(urlIdPerm2[0])));
                urlIdPerm3 = urlIdPerm1[0].Union(urlIdPerm2[0]);
                if (urlIdPerm3 == null) {
                    Console.WriteLine(("The union of " + firstPermission 
                        + " and \n\t" + secondPermission + " is null."));
                }
                else {
                    Console.WriteLine(("The union of " + firstPermission 
                        + " and \n\t" + secondPermission + " = \n\t" 
                        + ((UrlIdentityPermission)(urlIdPerm3)).
                        get_Url().ToString()));
                }
            }
            catch (System.Exception e) {
                Console.WriteLine(("An exception was thrown for union :" 
                    + e));
                returnValue = false;
            }
        }
    }
    return returnValue;
} //UnionDemo

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, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.