Export (0) Print
Expand All

UrlIdentityPermission Class

Defines the identity permission for the URL from which the code originates. This class cannot be inherited.

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

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class UrlIdentityPermission : CodeAccessPermission
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class UrlIdentityPermission extends CodeAccessPermission
SerializableAttribute 
ComVisibleAttribute(true) 
public final class UrlIdentityPermission extends CodeAccessPermission

The complete URL is considered, including the protocol (HTTP, HTTPS, FTP) and the file. For example, http://www.fourthcoffee.com/process/grind.htm is a complete URL.

URLs can be matched exactly or by a wildcard in the final position, for example: http://www.fourthcoffee.com/process/*. URLs can also contain a wildcard ("*") prefix at the dot delimiter. For example, the URL name string http://www.fourthcoffee.com/process/grind.htm/ is a subset of http://*.fourthcoffee.com/process/grind.htm/ and http://*.com/process/grind.htm/.

Caution noteCaution

UrlIdentityPermission grants permission for all paths to the file, including both the URL and the IP address. To Deny access to the file, you must Deny all possible paths to the file. For example, if http://www.fourthcoffee.com/process/grind.htm is located at IP address 192.168.238.241, to Deny access to http://www.fourthcoffee.com/process/grind.htm, you must Deny http://www.fourthcoffee.com/process/grind.htm, 192.168.238.241/grind.htm and any other path that you can use to access the code. Unfortunately, there are a myriad of ways URL paths can be phrased, so it is extremely difficult to block all paths through the use of Deny alone. A better technique to deal with multiple paths is to use a combination of PermitOnly and Deny. PermitOnly allows you to identify a finite set of URLs that you can provide access to, and then Deny allows you to explicitly select addresses from that set that you want to deny access to. For more information on this subject and the use of PermitOnly with Deny, see Canonicalization Problems Using Deny in the Using the Deny Method topic.

NoteNote

In the .NET Framework versions 1.0 and 1.1, identity permissions cannot have an Unrestricted permission state value. In the .NET Framework version 2.0, identity permissions can have any permission state value. This means that in version 2.0, identity permissions have the same behavior as permissions that implement the IUnrestrictedPermission interface. For information on executing version 2.0 applications with version 1.1 CAS policy, see <legacyV1CASPolicy> Element.

The following example demonstrates the behavior of the UrlIdentityPermission methods. The best use of this sample is to view results of the methods, not to show how the methods are used.

using System;
using System.Security;
using System.Security.Permissions;


public class UrlIdentityPermissionDemo
{
    private bool IsSubsetOfDemo()
    {

        bool returnValue = true;

        string url1, url2;
        UrlIdentityPermission urlIdPerm1, urlIdPerm2;

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

        urlGen1.ResetIndex();
        while (urlGen1.CreateUrl(out url1))
        {
            urlIdPerm1 = new UrlIdentityPermission(url1);
            Console.WriteLine("********************************************************\n");
            while (urlGen2.CreateUrl(out url2))
            {
                urlIdPerm2 = new UrlIdentityPermission(url2);
                string firstPermission = url1 == "" | url1 == null ? "null" : url1;
                string secondPermission = url2 == "" | url2 == null ? "null" : url2;
                if (urlIdPerm2 == null) continue;
                try
                {
                    if (urlIdPerm1.IsSubsetOf(urlIdPerm2))
                    {

                        Console.WriteLine(firstPermission + "\n is a subset of "
                            + secondPermission + "\n");
                    }
                    else
                    {
                        Console.WriteLine(firstPermission + "\n is not a subset of "
                            + secondPermission + "\n");
                    }

                }
                catch (Exception e)
                {
                    Console.WriteLine("An exception was thrown for subset :"
                        + url1 == "" ? "null." : url1 + "\n" + url2 == "" ? "null." : url2 + "\n" + e);
                }
            }
        }
        return returnValue;
    }
    // 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;

    }
    // Intersect creates and returns a new permission that is the intersection of the
    // current permission and the permission specified.
    private bool IntersectDemo()
    {

        bool returnValue = true;

        string url1, url2;
        UrlIdentityPermission urlIdPerm1, urlIdPerm2, 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();
            Console.WriteLine("********************************************************\n");
            while (urlGen2.CreateUrl(out url2))
            {
                urlIdPerm2 = new UrlIdentityPermission(url2);
                string firstPermission = url1 == "" | url1 == null ? "null" : url1;
                string secondPermission = url2 == "" | url2 == null ? "null" : url2;
                try
                {

                    urlIdPerm3 = (UrlIdentityPermission)urlIdPerm1.Intersect(urlIdPerm2);
                    if (urlIdPerm3 != null && urlIdPerm3.Url != null)
                    {

                        Console.WriteLine("The intersection of " + firstPermission
                            + " and \n\t" + secondPermission +
                            " = \n\t" + ((UrlIdentityPermission)urlIdPerm3).Url.ToString());
                    }
                    else
                    {
                        Console.WriteLine("The intersection of " + firstPermission + " and \n\t"
                            + secondPermission + " is null. ");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("An exception was thrown for the intersection : " + e);
                    returnValue = false;
                }
            }
        }

        return returnValue;

    }
    //Copy creates and returns an identical copy of the current permission.
    private bool CopyDemo()
    {

        bool returnValue = true;
        string url1;
        UrlIdentityPermission urlIdPerm1, urlIdPerm2;
        UrlGenerator urlGen1 = new UrlGenerator();
        UrlGenerator urlGen2 = new UrlGenerator();

        urlGen1.ResetIndex();
        while (urlGen1.CreateUrl(out url1))
        {
            urlIdPerm1 = new UrlIdentityPermission(url1);
            urlGen2.ResetIndex();
            Console.WriteLine("********************************************************\n");
            try
            {
                urlIdPerm2 = (UrlIdentityPermission)urlIdPerm1.Copy();
                if (urlIdPerm2 != null)
                {
                    Console.WriteLine("Result of copy = " + urlIdPerm2.ToString() + "\n");
                }
                else
                {
                    Console.WriteLine("Result of copy is null. \n");
                }
            }
            catch (Exception e)
            {
                {
                    if (url1 == "")
                    {
                        Console.WriteLine("The target UrlIdentityPermission is empty; copy failed.");

                    }
                    else
                        Console.WriteLine(e);
                }
                continue;
            }
        }
        return returnValue;
    }
    // ToXml creates an XML encoding of the permission and its current state; FromXml
    // reconstructs a permission with the specified state from the XML encoding.
    private bool ToFromXmlDemo()
    {

        bool returnValue = true;

        string url1;
        UrlIdentityPermission urlIdPerm1, urlIdPerm2;

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

        urlGen1.ResetIndex();
        while (urlGen1.CreateUrl(out url1))
        {
            urlIdPerm1 = new UrlIdentityPermission(url1);
            Console.WriteLine("********************************************************\n");
            urlGen2.ResetIndex();
            try
            {
                urlIdPerm2 = new UrlIdentityPermission(PermissionState.None);
                urlIdPerm2.FromXml(urlIdPerm1.ToXml());
                Console.WriteLine("Result of ToFromXml = " + urlIdPerm2.ToString() + "\n");

            }
            catch (Exception e)
            {
                Console.WriteLine("ToFromXml failed :" + urlIdPerm1.ToString() + e);
                continue;
            }
        }

        return returnValue;

    }
    // Invoke all demos.
    public bool runDemo()
    {

        bool ret = true;
        bool retTmp;
        // Call IsSubsetOf demo.
        retTmp = IsSubsetOfDemo();
        if (retTmp) Console.Out.WriteLine("IsSubset demo completed successfully.");
        else Console.Out.WriteLine("IsSubset demo failed.");
        ret = retTmp && ret;

        // Call Union demo.
        retTmp = UnionDemo();
        if (retTmp) Console.Out.WriteLine("Union demo completed successfully.");
        else Console.Out.WriteLine("Union demo failed.");
        ret = retTmp && ret;

        // Call Intersect demo.
        retTmp = IntersectDemo();
        if (retTmp) Console.Out.WriteLine("Intersect demo completed successfully.");
        else Console.Out.WriteLine("Intersect demo failed.");
        ret = retTmp && ret;


        // Call Copy demo.
        retTmp = CopyDemo();
        if (retTmp) Console.Out.WriteLine("Copy demo completed successfully.");
        else Console.Out.WriteLine("Copy demo failed.");
        ret = retTmp && ret;

        // Call ToFromXml demo.
        retTmp = ToFromXmlDemo();
        if (retTmp) Console.Out.WriteLine("ToFromXml demo completed successfully.");
        else Console.Out.WriteLine("ToFromXml demo failed.");
        ret = retTmp && ret;

        return (ret);

    }
    // Test harness.
    public static void Main(String[] args)
    {
        try
        {
            UrlIdentityPermissionDemo democase = new UrlIdentityPermissionDemo();
            bool ret = democase.runDemo();
            if (ret)
            {
                Console.Out.WriteLine("UrlIdentity demo completed successfully.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 100;
            }
            else
            {
                Console.Out.WriteLine("UrlIdentity demo failed.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 101;
            }
        }
        catch (Exception e)
        {
            Console.Out.WriteLine("UrlIdentity demo failed.");
            Console.WriteLine(e.ToString());
            Console.Out.WriteLine("Press the Enter key to exit.");
            string consoleInput = Console.ReadLine();
            System.Environment.ExitCode = 101;
        }
    }
}


// This class generates UrlIdentityPermission objects.

internal class UrlGenerator
{


    private string[] myUrl =
{
        "http://www.fourthcoffee.com/process/grind.htm","http://www.fourthcoffee.com/process/*",
    "http://www.fourthcoffee.com/*","http://www.fourthcoffee.com/process/*","http://www.contoso.com/math.asmx"};

    private int urlIndex = 0;

    public UrlGenerator()
    {
        ResetIndex();
    }

    public void ResetIndex()
    {
        urlIndex = 0;
    }
    // CreateUrl creates a UrlIdentityPermission.

    public bool CreateUrl(out string url)
    {


        if (urlIndex == myUrl.Length)
        {

            url = "";
            urlIndex++;
            return true;

        }
        if (urlIndex > myUrl.Length)
        {
            url = "";
            return false;
        }

        url = myUrl[urlIndex++];

        return true;
        
    }
} // End of UrlGenerator.


// This sample demonstrates the IsSubsetOf, Union, Intersect, 
// Copy, ToXml and FromXml methods
// of the UrlIdentityPermission class.

import System.*;
import System.Security.*;
import System.Security.Permissions.*;

/** @assembly CLSCompliant(true)
 */

public class UrlIdentityPermissionDemo
{
    // IsSubsetOf determines whether the current permission is a 
    // subset of the specified permission.
    private boolean IsSubsetOfDemo()
    {
        boolean returnValue = true;
        String url1[] = new String[1];
        String url2[] = new String[1];
        UrlIdentityPermission urlIdPerm1[] = new UrlIdentityPermission[1];
        UrlIdentityPermission urlIdPerm2[] = new UrlIdentityPermission[1];
        UrlGenerator urlGen1 = new UrlGenerator();
        UrlGenerator urlGen2 = new UrlGenerator();

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

                try {
                    if (urlIdPerm1[0].IsSubsetOf(urlIdPerm2[0])) {
                        Console.WriteLine((firstPermission 
                            + "\n is a subset of " + secondPermission + "\n"));
                    }
                    else {
                        Console.WriteLine((firstPermission 
                            + "\n is not a subset of " + secondPermission 
                            + "\n"));
                    }
                }
                catch (System.Exception e) {
                    Console.WriteLine(("An exception was thrown for subset :"
                    + url1 == "") ? "null." : (url1 + "\n" 
                        + url2 == "") ? "null." : url2 + "\n" + e);
                }
            }
        }
        return returnValue;
    } //IsSubsetOfDemo

    // 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

    // Intersect creates and returns a new permission that is 
    // the intersection of the
    // current permission and the permission specified.
    private boolean IntersectDemo()
    {
        boolean returnValue = true;
        String url1[] = new String[1];
        String url2[] = new String[1];
    
        UrlIdentityPermission urlIdPerm1[] = new UrlIdentityPermission[1];
        UrlIdentityPermission urlIdPerm2[] = new UrlIdentityPermission[1];
        UrlIdentityPermission urlIdPerm3[] = new UrlIdentityPermission[1];

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

        urlGen1.ResetIndex();
        while (urlGen1.CreateUrl(urlIdPerm1, url1)) {
            if (urlIdPerm1 == null) {
                continue;
            }
            Console.WriteLine("***************************************" 
                + "*******************\n");
            urlGen2.ResetIndex();
            Console.WriteLine("****************************************" 
                + "****************\n");
            while (urlGen2.CreateUrl(urlIdPerm2, url2)) {
                if (urlIdPerm2 == null) {
                    continue;
                }

                String firstPermission = (url1[0] == "" 
                    || url1[0] == null) ? "null" : url1[0];
                String secondPermission = (url2[0] == "" 
                    || url2[0] == null) ? "null" : url2[0];

                try {
                    urlIdPerm3[0] = ((UrlIdentityPermission)(urlIdPerm1[0].
                        Intersect(urlIdPerm2[0])));
                    if (urlIdPerm3[0] != null && urlIdPerm3[0].
                        get_Url() != null) {
                        Console.WriteLine(("The intersection of " 
                            + firstPermission + " and \n\t" + secondPermission 
                            + " = \n\t" 
                            + ((UrlIdentityPermission)(urlIdPerm3[0])).
                            get_Url().ToString()));
                    }
                    else {
                        Console.WriteLine(("The intersection of " 
                            + firstPermission + " and \n\t" 
                            + secondPermission + " is nu //IntersectDemoll. "));
                    }
                }
                catch (System.Exception e) {
                    Console.WriteLine(("An exception was thrown " 
                        + "for the intersection : " + e));
                    returnValue = false;
                }
            }
        }
        return returnValue;
    } //IntersectDemo

    //Copy creates and returns an identical copy of the current permission.
    private boolean CopyDemo()
    {
        boolean returnValue = true;
        String url1[] = new String[1];
        UrlIdentityPermission urlIdPerm1[] = new UrlIdentityPermission[1];
        UrlIdentityPermission urlIdPerm2[] = new UrlIdentityPermission[1];
        UrlGenerator urlGen1 = new UrlGenerator();
        UrlGenerator urlGen2 = new UrlGenerator();

        urlGen1.ResetIndex();
        while (urlGen1.CreateUrl(urlIdPerm1, url1)) {
            if (urlIdPerm1 == null) {
                continue;
            }
            urlGen2.ResetIndex();
            Console.WriteLine("**********************************************" 
                + "**********\n");
            try {
                urlIdPerm2[0] = ((UrlIdentityPermission)(urlIdPerm1[0].Copy()));
                if (urlIdPerm2 != null) {
                    Console.WriteLine(("Result of copy = " + urlIdPerm2[0].
                    ToString() + "\n"));
                }
                else {
                    Console.WriteLine("Result of copy is null. \n");
                }
            }
            catch (System.Exception e) {
                {
                    if (url1[0].Equals("")) {
                        Console.WriteLine("The target UrlIdentityPermission" 
                            + " is empty; copy failed.");
                    }
                    else {
                        Console.WriteLine(e);
                    }
                }
                continue;
            }
        }
        return returnValue;
    } //CopyDemo

    // ToXml creates an XML encoding of the permission and 
    // its current state; FromXml
    // reconstructs a permission with the specified state from
    // the XML encoding.
    private boolean ToFromXmlDemo()
    {
        boolean returnValue = true;
        String url1[] = new String[1];
        UrlIdentityPermission urlIdPerm1[] = new UrlIdentityPermission[1];
        UrlIdentityPermission urlIdPerm2[] = new UrlIdentityPermission[1];
        UrlGenerator urlGen1 = new UrlGenerator();
        UrlGenerator urlGen2 = new UrlGenerator();

        urlGen1.ResetIndex();
        while (urlGen1.CreateUrl(urlIdPerm1, url1)) {
            if (urlIdPerm1 == null) {
                continue;
            }
            Console.WriteLine("********************************************" 
                + "************\n");
            urlGen2.ResetIndex();
            try {
                urlIdPerm2[0] = new UrlIdentityPermission(PermissionState.None);
                urlIdPerm2[0].FromXml(urlIdPerm1[0].ToXml());
                Console.WriteLine(("Result of ToFromXml = " 
                    + urlIdPerm2[0].ToString() + "\n"));
            }
            catch (System.Exception e) {
                Console.WriteLine(("ToFromXml failed :" 
                    + urlIdPerm1.ToString() + e));
                continue;
            }
        }
        return returnValue;
    } //ToFromXmlDemo

    // Invoke all demos.
    public boolean runDemo()
    {
        boolean ret = true;
        boolean retTmp;

        // Call IsSubsetOf demo.
        retTmp = IsSubsetOfDemo();
        if (retTmp) {
            Console.get_Out().WriteLine("IsSubset demo completed " 
                + "successfully.");
        }
        else {
            Console.get_Out().WriteLine("IsSubset demo failed.");
        }
        ret = retTmp && ret;

        // Call Union demo.
        retTmp = UnionDemo();
        if (retTmp) {
            Console.get_Out().WriteLine("Union demo completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("Union demo failed.");
        }
        ret = retTmp && ret;

        // Call Intersect demo.
        retTmp = IntersectDemo();
        if (retTmp) {
            Console.get_Out().WriteLine("Intersect demo completed " 
                + "successfully.");
        }
        else {
            Console.get_Out().WriteLine("Intersect demo failed.");
        }
        ret = retTmp && ret;

        // Call Copy demo.
        retTmp = CopyDemo();
        if (retTmp) {
            Console.get_Out().WriteLine("Copy demo completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("Copy demo failed.");
        }
        ret = retTmp && ret;

        // Call ToFromXml demo.
        retTmp = ToFromXmlDemo();
        if (retTmp) {
            Console.get_Out().WriteLine("ToFromXml demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("ToFromXml demo failed.");
        }

        ret = retTmp && ret;
        return ret;
    } //runDemo

    // Test harness.
    public static void main(String[] args)
    {
        try {
            UrlIdentityPermissionDemo democase = new 
            UrlIdentityPermissionDemo();
            boolean ret = democase.runDemo();

            if (ret) {
                Console.get_Out().WriteLine("UrlIdentity demo completed" 
                    + " successfully.");
                Console.get_Out().WriteLine("Press the Enter key to exit.");
                String consoleInput = Console.ReadLine();
                Environment.set_ExitCode(100);
            }
            else {
                Console.get_Out().WriteLine("UrlIdentity demo failed.");
                Console.get_Out().WriteLine("Press the Enter key to exit.");
                String consoleInput = Console.ReadLine();
                Environment.set_ExitCode(101);
            }
        }
        catch (System.Exception e) {
            Console.get_Out().WriteLine("UrlIdentity demo failed.");
            Console.WriteLine(e.ToString());
            Console.get_Out().WriteLine("Press the Enter key to exit.");
            String consoleInput = Console.ReadLine();
            Environment.set_ExitCode(101);
        }
    } //main
} //UrlIdentityPermissionDemo

// This class generates UrlIdentityPermission objects.
class UrlGenerator
{
    private String myUrl[] = { 
        "http://www.fourthcoffee.com/process/grind.htm",
        "http://www.fourthcoffee.com/process/*", 
        "http://www.fourthcoffee.com/*", 
        "http://www.fourthcoffee.com/process/*",
        "http://www.contoso.com/math.asmx"};

    private int urlIndex = 0;

    public UrlGenerator() 
    {
        ResetIndex();
    } //UrlGenerator

    public void ResetIndex()
    {
        urlIndex = 0;
    } //ResetIndex


    // CreateUrl creates a UrlIdentityPermission.
    public boolean CreateUrl(UrlIdentityPermission urlPerm[], String url[])
    {
        UrlIdentityPermission urlP = null;
        if (urlIndex == myUrl.length) {
            urlPerm[0] = new UrlIdentityPermission(PermissionState.None);

            url[0] = "";
            urlIndex++;
            return true;
        }
        if (urlIndex > myUrl.length) {
            urlPerm = null;
            url[0] = "";
            return false;
        }
        url[0] = myUrl[urlIndex++];
        try {
            urlP = new UrlIdentityPermission(url[0]);
            urlPerm[0] = urlP;
            return true;
        }
        catch (System.Exception e) {
            Console.WriteLine(("Cannot create UrlIdentityPermission : " 
                + url + " " + e));
            urlPerm[0] = new UrlIdentityPermission(PermissionState.None);
            url[0] = "";
            return true;
        }
    } //CreateUrl
} //UrlGenerator

System.Object
   System.Security.CodeAccessPermission
    System.Security.Permissions.UrlIdentityPermission

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

Community Additions

ADD
Show:
© 2014 Microsoft