Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

SiteIdentityPermission Class

Defines the identity permission for the Web site 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 SiteIdentityPermission : CodeAccessPermission
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class SiteIdentityPermission extends CodeAccessPermission
SerializableAttribute 
ComVisibleAttribute(true) 
public final class SiteIdentityPermission extends CodeAccessPermission

Using this class, it is possible to ensure that callers are from a specific Web site. Site identity is only defined for code from URLs with the protocols of HTTP, HTTPS, and FTP. A site is the string between the "//" after the protocol of a URL and the following "/", if present, for example, www.fourthcoffee.com in the URL http://www.fourthcoffee.com/process/grind.htm. This excludes port numbers. If a given URL is http://www.fourthcoffee.com:8000/, the site is www.fourthcoffee.com, not www.fourthcoffee.com:8000.

Sites can be matched exactly, or by a wildcard ("*") prefix at the dot delimiter. For example, the site name string *.fourthcoffee.com matches fourthcoffee.com as well as www.fourthcoffee.com. Without a wildcard, the site name must be a precise match. The site name string * will match any site, but will not match code that has no site evidence.

Caution noteCaution

SiteIdentityPermission grants permission for all paths to the site, including both the URL and the IP address. To Deny access to a site, you must Deny all possible paths to the site. For example, if www.fourthcoffee.com is located at IP address 192.168.238.241, to Deny access to www.fourthcoffee.com, you must Deny www.fourthcoffee.com, 192.168.238.241 and any other path that you can use to access the site. A better technique to deal with multiple paths is to use a combination of PermitOnly and Deny. 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.

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

[assembly: CLSCompliant(true)]

public class SiteIdentityPermissionDemo
{
    // IsSubsetOf determines whether the current permission is a subset of the specified permission.
    private bool IsSubsetOfDemo()
    {
        bool returnCodeCode = true;

        String site1, site2;
        SiteIdentityPermission siteIdPerm1, siteIdPerm2;

        SiteGenerator siteGen1 = new SiteGenerator();
        SiteGenerator siteGen2 = new SiteGenerator();

        siteGen1.ResetIndex();
        while (siteGen1.CreateSite(out site1))
        {
            siteIdPerm1 = siteGen1.CreatePerm(site1);
            if (siteIdPerm1 == null ) continue;
            siteGen2.ResetIndex();
            Console.WriteLine("**************************************************************************");
            while (siteGen2.CreateSite(out site2))
            {
                try
                {
                    siteIdPerm2 = siteGen2.CreatePerm(site2);
                    if (siteIdPerm2 == null ) continue;

                    if (siteIdPerm1.IsSubsetOf(siteIdPerm2))
                    {
                        Console.WriteLine(site1 + " is a subset of " + site2);
                    }
                    else
                    {
                        Console.WriteLine(site1 + " is not a subset of " + site2);

                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("An exception was thrown : " + e);
                    return false;
                }

            }
        }
        return returnCodeCode;

    }
    // Union creates a new permission that is the union of the current permission
    // and the specified permission.
    private bool UnionDemo()
    {
        bool returnCodeCode = true;
        String site1, site2;
        SiteIdentityPermission siteIdPerm1, siteIdPerm2, p3;

        SiteGenerator siteGen1 = new SiteGenerator();
        SiteGenerator siteGen2 = new SiteGenerator();

        siteGen1.ResetIndex();
        while (siteGen1.CreateSite(out site1))
        {
            siteIdPerm1 = siteGen1.CreatePerm(site1);
            if (siteIdPerm1 == null ) continue;
            siteGen2.ResetIndex();
            Console.WriteLine("**************************************************************************");
            while (siteGen2.CreateSite(out site2))
            {
                siteIdPerm2 = siteGen2.CreatePerm(site2);
                if (siteIdPerm2 == null ) continue;
                String firstSite = site1 == null ? "null" : site1;
                String secondSite = site2 == null ? "null" : site2;
                try
                {
                    p3 = (SiteIdentityPermission)siteIdPerm1.Union(siteIdPerm2);
                    String thirdSite = p3.Site == null ? "null" : p3.Site;

                    if (p3 != null)
                    {
                        Console.WriteLine("The union of " + firstSite + " and \n\t" + secondSite + " = \n\t"
                            + thirdSite + "\n");

                    }
                    else
                    {
                        Console.WriteLine("The union of " + firstSite + " and \n\t" + secondSite + " = null.\n");
                    }
                }
                catch (Exception e)
                {
                    // Expected exception.
                    Console.WriteLine(e.Message + "\n\t" + firstSite + " and " + secondSite + "\n");
                }
            }
        }
        return returnCodeCode;

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

        bool returnCodeCode = true;

        String site1, site2;
        SiteIdentityPermission siteIdPerm1, siteIdPerm2, p3;

        SiteGenerator siteGen1 = new SiteGenerator();
        SiteGenerator siteGen2 = new SiteGenerator();

        siteGen1.ResetIndex();
        while (siteGen1.CreateSite(out site1))
        {
            siteIdPerm1 = siteGen1.CreatePerm(site1);
            if (siteIdPerm1 == null ) continue;
            siteGen2.ResetIndex();
            Console.WriteLine("**************************************************************************");
            while (siteGen2.CreateSite(out site2))
            {
                siteIdPerm2 = siteGen2.CreatePerm(site2);
                if (siteIdPerm2 == null ) continue;
                String firstSite = site1 == null ? "null" : site1;
                String secondSite = site2 == null ? "null" : site2;
                try
                {
                    p3 = (SiteIdentityPermission)siteIdPerm1.Intersect(siteIdPerm2);
                    String thirdSite = p3.Site == null ? "null" : p3.Site;

                    if (p3 != null)
                    {
                        Console.WriteLine("The intersection of " + firstSite + " and \n\t" + secondSite + " = " + thirdSite + "\n");

                    }
                    else
                    {
                        Console.WriteLine("The intersection of " + firstSite + " and \n\t" + secondSite + " = null.\n");
                    }
                }
                catch
                {
                    Console.WriteLine("The intersection of " + firstSite + " and \n\t" + secondSite + " = null.\n");

                }


            }
        }


        return returnCodeCode;

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

        bool returnCodeCode = true;

        String site1;
        SiteIdentityPermission siteIdPerm1, siteIdPerm2;
        SiteGenerator siteGen1 = new SiteGenerator();
        SiteGenerator siteGen2 = new SiteGenerator();

        siteGen1.ResetIndex();
        while (siteGen1.CreateSite(out site1))
        {
            siteIdPerm1 = siteGen1.CreatePerm(site1);
            if (siteIdPerm1 == null ) continue;
            siteGen2.ResetIndex();
            Console.WriteLine("**************************************************************************");
            try
            {
                siteIdPerm2 = (SiteIdentityPermission)siteIdPerm1.Copy();
                if (siteIdPerm2 != null)
                {
                    Console.WriteLine("The copy of " + siteIdPerm2.ToString() + " succeeded.\n");
                }

            }
            catch (Exception e)
            {
                Console.WriteLine("The copy failed : " + siteIdPerm1.ToString() + e);
                continue;
            }
        }
        return returnCodeCode;

    }
    // 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 returnCodeCode = true;

        String site1;
        SiteIdentityPermission siteIdPerm1, siteIdPerm2;
        SiteGenerator siteGen1 = new SiteGenerator();
        SiteGenerator siteGen2 = new SiteGenerator();

        siteGen1.ResetIndex();
        while (siteGen1.CreateSite(out site1))
        {
            siteIdPerm1 = siteGen1.CreatePerm(site1);
            if (siteIdPerm1 == null ) continue;
            siteGen2.ResetIndex();
            Console.WriteLine("**************************************************************************");
            try
            {
                siteIdPerm2 = new SiteIdentityPermission(PermissionState.None);
                siteIdPerm2.FromXml(siteIdPerm1.ToXml());
                bool result = siteIdPerm2.Equals(siteIdPerm1);
                if (siteIdPerm2.IsSubsetOf(siteIdPerm1) && siteIdPerm1.IsSubsetOf(siteIdPerm2))
                {
                    Console.WriteLine("Result of ToFromXml = " + siteIdPerm2.ToString());
                }
                else
                {
                    Console.WriteLine(siteIdPerm2.ToString());
                    Console.WriteLine(siteIdPerm1.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("ToFromXml failed. " + e);
                continue;
            }

        }


        return returnCodeCode;

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

        bool returnCode = true;
        bool tempReturnCode;
        // Call the IsSubsetOf demo.
        if (tempReturnCode = IsSubsetOfDemo()) Console.Out.WriteLine("The IsSubsetOf demo completed successfully.");
        else
            Console.Out.WriteLine("subsetDemo failed.");
        returnCode = tempReturnCode && returnCode;

        // Call the Union demo.
        if (tempReturnCode = UnionDemo()) Console.Out.WriteLine("The Union demo completed successfully.");
        else
            Console.Out.WriteLine("UnionDemo failed.");
        returnCode = tempReturnCode && returnCode;

        // Call the Intersect demo.
        if (tempReturnCode = IntersectDemo()) Console.Out.WriteLine("The Intersect demo completed successfully.");
        else
            Console.Out.WriteLine("IntersectDemo failed.");
        returnCode = tempReturnCode && returnCode;


        // Call the Copy demo.
        if (tempReturnCode = CopyDemo()) Console.Out.WriteLine("The Copy demo completed successfully.");
        else
            Console.Out.WriteLine("CopyDemo failed.");
        returnCode = tempReturnCode && returnCode;

        // Call the ToFromXML demo.
        if (tempReturnCode = ToFromXmlDemo()) Console.Out.WriteLine("The ToFromXML demo completed successfully.");
        else
            Console.Out.WriteLine("ToFromXmlDemo failed.");
        returnCode = tempReturnCode && returnCode;

        return (returnCode);

    }
    // Test harness.
    public static void Main(String[] args)
    {
        try
        {
            SiteIdentityPermissionDemo testcase = new SiteIdentityPermissionDemo();
            bool returnCode = testcase.RunDemo();
            if (returnCode)
            {
                Console.Out.WriteLine("The SiteIdentityPermission demo completed successfully.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 100;
            }
            else
            {
                Console.Out.WriteLine("The SiteIdentityPermission 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("The SiteIdentityPermission 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 SiteIdentityPermission objects.

internal class SiteGenerator
{

    private string[] siteArray =
        // Replace this array with Web sites of your own choosing.
{
    "www.fourthcoffee.com",
    "www.tailspintoys.com",
    "*.fourthcoffee.com",
    "*.com",
    ""};

    private int siteIndex = 0;

    public SiteGenerator()
    {
        ResetIndex();
    }

    public void ResetIndex()
    {

        siteIndex = 0;

    }
    
    // CreateSite creates a SiteIdentityPermission.
    public bool CreateSite(out string site)
    {
        if (siteIndex >= siteArray.Length)
        {

            site = "null";
            return false;

        }

        site = siteArray[siteIndex++];
        return true;

        
    }
   
    public SiteIdentityPermission CreatePerm(string site)
    {
        SiteIdentityPermission sitePerm;
        try
        {
            string newSite = site;
            sitePerm = new SiteIdentityPermission(newSite);
            return sitePerm;
        }
        catch (ArgumentException e)
        {
            Console.WriteLine("An ArgumentException was thrown: " + e.Message);
            if (site != null && site != "")
            {
                Console.WriteLine(site + " is an invalid site.");
            }
            else if (site == "")
            {
                Console.WriteLine("An empty string signifies an invalid site.");
                site = "an empty string";
            }
            return null;
        }
    }
} // End of SiteGenerator.


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

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

/** @assembly CLSCompliant(true)
 */

public class SiteIdentityPermissionDemo
{
    // IsSubsetOf determines whether the current permission is a subset of 
    // the specified permission.
    private boolean IsSubsetOfDemo()
    {
        boolean returnCodeCode = true;
        String site1[] = new String[1];
        String site2[] = new String[1];
        boolean successFlag[] = new boolean[1];
        SiteIdentityPermission siteIdPerm1[] = new SiteIdentityPermission[1];
        SiteIdentityPermission siteIdPerm2[] = new SiteIdentityPermission[1];
        SiteGenerator siteGen1 = new SiteGenerator();
        SiteGenerator siteGen2 = new SiteGenerator();

        siteGen1.ResetIndex();
        while (siteGen1.CreateSite(siteIdPerm1, site1, successFlag))
        {
            if (siteIdPerm1[0] == null | successFlag[0] == false) {
                continue;
            }

            siteGen2.ResetIndex();
            Console.WriteLine("**************************************" 
                + "************************************");
            while (siteGen2.CreateSite(siteIdPerm2, site2, successFlag)) {
                try {
                    if (siteIdPerm2[0] == null | successFlag[0] == false) {
                        continue;
                    }
                    if (siteIdPerm1[0].IsSubsetOf(siteIdPerm2[0])) {
                        Console.WriteLine((site1[0] + " is a subset of " 
                            + site2[0]));
                    }
                    else {
                        Console.WriteLine((site1[0] + " is not a subset of " 
                            + site2[0]));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(("An exception was thrown : " + e));
                    return false;
                }
            }
        }

        return returnCodeCode;
    } //IsSubsetOfDemo
      
    // Union creates a new permission that is the union of the current 
    // permission
    // and the specified permission.
    private boolean UnionDemo() 
    {
        boolean returnCodeCode = true;
        
        String site1[] = new String[1];
        String site2[] = new String[1];
        boolean successFlag[] = new boolean[1];
        SiteIdentityPermission siteIdPerm1[] = new SiteIdentityPermission[1];
        SiteIdentityPermission siteIdPerm2[] = new SiteIdentityPermission[1];
        SiteIdentityPermission p3 = null;
          
        SiteGenerator siteGen1 =  new SiteGenerator();
        SiteGenerator siteGen2 =  new SiteGenerator();
        
        siteGen1.ResetIndex();
        while(siteGen1.CreateSite(siteIdPerm1, site1, successFlag)) {
            if (siteIdPerm1[0] == null | successFlag[0] == false) {
                continue ;
            }

            siteGen2.ResetIndex();
            Console.WriteLine("****************************************" 
                + "**********************************");
            while(siteGen2.CreateSite(siteIdPerm2, site2, successFlag)) {
                if (siteIdPerm2[0] == null | successFlag[0] == false) {
                    continue ;
                }
                String firstSite = (site1[0] == null) ? "null" : site1[0];
                String secondSite = (site2[0] == null) ? "null" : site2[0];
                try {
                    p3 =((SiteIdentityPermission)(
                    siteIdPerm1[0].Union(siteIdPerm2[0])));
                    String thirdSite = (p3.get_Site() == null) ? 
                    "null" : p3.get_Site();
                           
                    if (p3  != null) {
                        Console.WriteLine(("The union of " + firstSite 
                            + " and \n\t" + secondSite + " = \n\t" 
                            + thirdSite + "\n"));
                    }
                    else {
                        Console.WriteLine(("The union of " + firstSite 
                            + " and \n\t" + secondSite + " = null.\n"));
                    }
                }
                catch(Exception exp) {
                    // Expected exception, result of the union is null.
                    Console.WriteLine(("The union of " + firstSite 
                        + " and \n\t" + secondSite + " = null.\n"));
                }
            }
        }
        return returnCodeCode ;
   }

   // Intersect creates and returns a new permission that is the intersection 
   // of the current permission and the permission specified.
   private boolean IntersectDemo() 
   {
        boolean returnCodeCode = true;

        String site1[] = new String[1];
        String site2[] = new String[1];
        boolean successFlag[] = new boolean[1];
        SiteIdentityPermission siteIdPerm1[] = new SiteIdentityPermission[1];
        SiteIdentityPermission siteIdPerm2[] = new SiteIdentityPermission[1];
        SiteIdentityPermission p3 = null;
        
        SiteGenerator siteGen1 =  new SiteGenerator();
        SiteGenerator siteGen2 =  new SiteGenerator();
            siteGen1.ResetIndex();

        while(siteGen1.CreateSite(siteIdPerm1, site1, successFlag)) {
            if (siteIdPerm1 == null | successFlag[0] == false) {
                continue ;
            }
            siteGen2.ResetIndex();
            Console.WriteLine("***************************************" 
                + "***********************************");
            while(siteGen2.CreateSite(siteIdPerm2, site2, successFlag)) {
                if (siteIdPerm2[0] == null | successFlag[0] == false) {
                    continue ;
                }
                String firstSite = (site1[0] == null) ? "null" : site1[0];
                String secondSite = (site2[0] == null) ? "null" : site2[0];
                try {
                    p3 =((SiteIdentityPermission)(siteIdPerm1[0].
                        Intersect(siteIdPerm2[0])));
                    String thirdSite = (p3.get_Site() == null) ? 
                        "null" : p3.get_Site();
                   
                    if (p3  != null) {
                        Console.WriteLine(("The intersection of " + firstSite 
                            + " and \n\t" + secondSite + " = " 
                            + thirdSite + "\n"));
                    }
                    else {
                        Console.WriteLine(("The intersection of " + firstSite 
                            + " and \n\t" + secondSite + " = null.\n"));
                    }
                }
                catch(Exception exp) {
                    Console.WriteLine(("The intersection of " + firstSite 
                        + " and \n\t" + secondSite + " = null.\n"));
                }
            }
        }
        return returnCodeCode ;
   } //IntersectDemo

   //Copy creates and returns an identical copy of the current permission.
   private boolean CopyDemo() 
   {
        boolean returnCodeCode = true;
      
        String site1[] = new String[1];
        SiteIdentityPermission siteIdPerm1[] = new SiteIdentityPermission[1];
        SiteIdentityPermission siteIdPerm2[] = new SiteIdentityPermission[1];
        boolean successFlag[] = new boolean[1];
      
        SiteGenerator siteGen1 =  new SiteGenerator();
        SiteGenerator siteGen2 =  new SiteGenerator();
      
        siteGen1.ResetIndex();
        while(siteGen1.CreateSite(siteIdPerm1, site1, successFlag)) {
        if (siteIdPerm1[0] == null | successFlag[0] == false) {
            continue ;
        }
        siteGen2.ResetIndex();
        Console.WriteLine("*********************************" 
            + "*****************************************");
        try {
            siteIdPerm2[0] =((SiteIdentityPermission)(siteIdPerm1[0].Copy()));
            if (siteIdPerm2  != null) {
                Console.WriteLine(("The copy of " 
                    + siteIdPerm2[0].ToString() + " succeeded.\n"));
            }
        }
        catch(Exception e) {
            Console.WriteLine(("The copy failed : " 
                + siteIdPerm1[0].ToString() + e));
           continue ;
         }
      }
     return returnCodeCode ;
   } //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 returnCodeCode = true;
        String site1[] = new String[1];
        SiteIdentityPermission siteIdPerm1[] = new SiteIdentityPermission[1];
        SiteIdentityPermission siteIdPerm2[] = new SiteIdentityPermission[1];
        boolean successFlag[] = new boolean[1];
      
        SiteGenerator siteGen1 =  new SiteGenerator();
        SiteGenerator siteGen2 =  new SiteGenerator();
      
        siteGen1.ResetIndex();
        while(siteGen1.CreateSite(siteIdPerm1, site1, successFlag)) {
            if (siteIdPerm1[0] == null | successFlag[0] == false) {
                continue ;
         }
         siteGen2.ResetIndex();
         Console.WriteLine("*********************************************" 
            + "*****************************");
        try {
            siteIdPerm2[0] = new SiteIdentityPermission(PermissionState.None);
            siteIdPerm2[0].FromXml(siteIdPerm1[0].ToXml());
            boolean result = siteIdPerm2[0].Equals(siteIdPerm1[0]);
            if (siteIdPerm2[0].IsSubsetOf(siteIdPerm1[0]) && 
                siteIdPerm1[0].IsSubsetOf(siteIdPerm2[0])) {
                Console.WriteLine(("Result of ToFromXml = " 
                    + siteIdPerm2[0].ToString()));
            }
            else {
                Console.WriteLine(siteIdPerm2[0].ToString());
                Console.WriteLine(siteIdPerm1[0].ToString());
            }
        }
        catch(Exception e) {
            Console.WriteLine(("ToFromXml failed. " + e));
            continue ;
         }
      }
      return returnCodeCode ;
   } //ToFromXmlDemo
    
   // Invoke all demos.
   public boolean RunDemo() 
   {
        boolean returnCode = true;
        boolean tempReturnCode;
        // Call the IsSubsetOf demo.
        if (tempReturnCode = IsSubsetOfDemo()) {
            Console.get_Out().WriteLine("The IsSubsetOf demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("subsetDemo failed.");
        }
        returnCode = tempReturnCode && returnCode;
          
        // Call the Union demo.
        if (tempReturnCode = UnionDemo()) {
            Console.get_Out().WriteLine(
                "The Union demo completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("UnionDemo failed.");
        }
        returnCode = tempReturnCode && returnCode;
          
        // Call the Intersect demo.
        if (tempReturnCode = IntersectDemo()) {
            Console.get_Out().WriteLine("The Intersect demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("IntersectDemo failed.");
        }
        returnCode = tempReturnCode && returnCode;
          
        // Call the Copy demo.
        if (tempReturnCode = CopyDemo()) {
            Console.get_Out().WriteLine("The Copy demo completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("CopyDemo failed.");
        }
        returnCode = tempReturnCode && returnCode;
          
        // Call the ToFromXML demo.
        if (tempReturnCode = ToFromXmlDemo()) {
            Console.get_Out().WriteLine("The ToFromXML demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("ToFromXmlDemo failed.");
        }
        returnCode = tempReturnCode && returnCode;
          
        return returnCode ;
   } //RunDemo
    
   // Test harness.
   public static void main(String[] args)
   {
        try {
            SiteIdentityPermissionDemo testcase =  
            new SiteIdentityPermissionDemo();
            boolean returnCode = testcase.RunDemo();
            if (returnCode) {
                Console.get_Out().WriteLine("The SiteIdentityPermission " 
                    + "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("The SiteIdentityPermission " 
                    + "demo failed.");
                Console.get_Out().WriteLine("Press the Enter key to exit.");
                String consoleInput = Console.ReadLine();
                Environment.set_ExitCode(101);
            }
        }
        catch(Exception e) {
            Console.get_Out().WriteLine("The SiteIdentityPermission " 
                + "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
} //SiteIdentityPermissionDemo

// This class generates SiteIdentityPermission objects.
class SiteGenerator
{
    private String siteArray[] =  {"www.northwindtraders.northwindtraders.com", 
        "*.northwindtraders.com", "*.margiestravel.com", "northwindtraders.com", 
        "*northwindtraders.com", ""};
    // Replace this array with Web sites of your own choosing.
   
    private int siteIndex = 0;
      
    public SiteGenerator() 
    {
        ResetIndex();
    } //SiteGenerator
   
    public void ResetIndex() 
    {
        siteIndex = 0;
    } //ResetIndex
    
    // CreateSite creates a SiteIdentityPermission.
    public boolean CreateSite(SiteIdentityPermission sitePerm[], 
        String site[], boolean successFlag[]) 
    {
        successFlag[0] = true;
        if (siteIndex >= siteArray.length) {
            sitePerm[0] = new SiteIdentityPermission(PermissionState.None);
            site[0] = "null";
            return false ;
        }
        site[0] = siteArray[siteIndex++];
        try {
            sitePerm[0] = new SiteIdentityPermission(site[0]);
            return true ;
        }
        catch(ArgumentException e) {
            Console.WriteLine(("An ArgumentException was thrown: " 
                + e.get_Message()));
            successFlag[0] = false;
            if (site[0]  != null && site[0] != "") {
                Console.WriteLine((site[0] + " is an invalid site."));
            }
            else {
                if (site[0].equalsIgnoreCase("") == true) {
                    Console.WriteLine("An empty string signifies " 
                        + "an invalid site.");
                    site[0] = "an empty string";
                }
                else {
                    sitePerm[0] = 
                    new SiteIdentityPermission(PermissionState.None);
                    Console.WriteLine(e);
                    site[0] = "null";
                    return false ;
                }
            }
            sitePerm[0] = new SiteIdentityPermission(PermissionState.None);
            return true ;
        }
    } //CreateSite
} //SiteGenerator

System.Object
   System.Security.CodeAccessPermission
    System.Security.Permissions.SiteIdentityPermission
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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.