Freigeben über


SiteIdentityPermission-Klasse

Definiert die Identitätsberechtigung für die Website, aus der der Code stammt. Diese Klasse kann nicht vererbt werden.

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

Syntax

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class SiteIdentityPermission
    Inherits CodeAccessPermission
'Usage
Dim instance As SiteIdentityPermission
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class SiteIdentityPermission : CodeAccessPermission
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class SiteIdentityPermission sealed : public CodeAccessPermission
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class SiteIdentityPermission extends CodeAccessPermission
SerializableAttribute 
ComVisibleAttribute(true) 
public final class SiteIdentityPermission extends CodeAccessPermission

Hinweise

Durch die Verwendung dieser Klasse kann sichergestellt werden, dass der Aufruf von einer bestimmten Website aus erfolgte. Die Site-Identität wird nur bei Code von URLs mit den Protokollen HTTP, HTTPS und FTP definiert. Eine Site ist die Zeichenfolge zwischen dem "//", das nach dem Protokoll eines URL steht, und dem folgenden "/" (sofern vorhanden), z. B. www.fourthcoffee.com im URL https://www.fourthcoffee.com/process/grind.htm. Anschlussnummern werden hierdurch ausgeschlossen. Wenn ein URL https://www.fourthcoffee.com:8000/ lautet, ist die entsprechende Site www.fourthcoffee.com, nicht www.fourthcoffee.com:8000.

Die Site kann mit dem genauen Namen oder mithilfe eines vorangestellten Platzhalters ("*") vor dem Trennpunkt angegeben werden. Die Zeichenfolge für den Sitenamen *.fourthcoffee.com stimmt sowohl mit fourthcoffee.com als auch mit www.fourthcoffee.com überein. Ohne Platzhalterzeichen muss der angegebene Sitename genau dem tatsächlichen Namen entsprechen. Die Zeichenfolge * für den Sitenamen entspricht allen Sites, nicht jedoch Code ohne Sitebeweis.

Warnung

Die SiteIdentityPermission-Klasse gewährt die Berechtigung für alle Pfade zur Site, einschließlich URL und IP-Adresse. Um für den Zugriff auf eine Site auf Deny festzulegen, müssen Sie die Deny-Methode für alle möglichen Pfade der Site festlegen. Wenn z. B. www.fourthcoffee.com die IP-Adresse 192.168.238.241 hat und Sie den Zugriff auf www.fourthcoffee.com mit Deny verweigern möchten, müssen Sie die Deny-Methode sowohl für www.fourthcoffee.com als auch für 192.168.238.241 und alle anderen Pfade festlegen, über die auf die Site zugegriffen werden kann. Ein einfacheres Verfahren für den Umgang mit mehreren Pfaden besteht in der Kombination aus PermitOnly-Methode und Deny-Methode. Weitere Informationen über dieses Thema und die Verwendung der PermitOnly-Methode mit der Deny-Methode finden Sie unter Canonicalization Problems Using Deny im Thema Verwenden der Deny-Methode.

Hinweis

In .NET Framework, Versionen 1.0 und 1.1, können Identitätsberechtigungen nicht den Berechtigungszustandswert Unrestricted haben. In .NET Framework, Version 2.0, können Identitätsberechtigungen jeden Berechtigungszustandswert haben. Das heißt, dass Identitätsberechtigungen in Version 2.0 über das gleiche Verhalten verfügen wie Berechtigungen, die die IUnrestrictedPermission-Schnittstelle implementieren. Informationen über die Ausführung von Version 2.0-Anwendungen mit der Version 1.1-Zertifizierungsstellenrichtlinie finden Sie unter <legacyV1CASPolicy>-Element.

Beispiel

Imports System
Imports System.Security
Imports System.Security.Permissions
Imports Microsoft.VisualBasic

<Assembly: CLSCompliant(True)> 

Public Class SiteIdentityPermissionDemo

    ' IsSubsetOf determines whether the current permission is a subset of the specified permission.
    Private Function IsSubsetOfDemo() As Boolean
        Dim returnCodeCode As Boolean = True

        Dim site1 As [String] = ""
        Dim site2 As [String] = ""
        Dim siteIdPerm1, siteIdPerm2 As SiteIdentityPermission

        Dim siteGen1 As New SiteGenerator()
        Dim siteGen2 As New SiteGenerator()

        siteGen1.ResetIndex()
        While siteGen1.CreateSite(site1)
            siteIdPerm1 = siteGen1.CreatePerm(site1)
            If siteIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            siteGen2.ResetIndex()
            Console.WriteLine("**************************************************************************")
            While siteGen2.CreateSite(site2)
                Try
                    siteIdPerm2 = siteGen2.CreatePerm(site2)
                    If siteIdPerm2 Is Nothing Then
                        GoTo ContinueWhile2
                    End If
                    If siteIdPerm1.IsSubsetOf(siteIdPerm2) Then
                        Console.WriteLine((site1 & " is a subset of " & site2))
                    Else
                        Console.WriteLine((site1 & " is not a subset of " & site2))
                    End If
                Catch e As Exception
                    Console.WriteLine(("An exception was thrown : " & e.ToString()))
                    Return False
                End Try
ContinueWhile2:
            End While
ContinueWhile1:
        End While


        Return returnCodeCode
    End Function 'IsSubsetOfDemo

    ' Union creates a new permission that is the union of the current permission 
    ' and the specified permission.
    Private Function UnionDemo() As Boolean
        Dim returnCodeCode As Boolean = True
        Dim site1 As [String] = ""
        Dim site2 As [String] = ""
        Dim siteIdPerm1, siteIdPerm2, p3 As SiteIdentityPermission

        Dim siteGen1 As New SiteGenerator()
        Dim siteGen2 As New SiteGenerator()

        siteGen1.ResetIndex()
        While siteGen1.CreateSite(site1)
            siteIdPerm1 = siteGen1.CreatePerm(site1)
            If siteIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            siteGen2.ResetIndex()
            Console.WriteLine("**************************************************************************")
            While siteGen2.CreateSite(site2)
                siteIdPerm2 = siteGen2.CreatePerm(site2)
                If siteIdPerm2 Is Nothing Then
                    GoTo ContinueWhile2
                End If
                Dim firstSite As [String] = IIf(site1 Is Nothing, "null", site1)
                Dim secondSite As [String] = IIf(site2 Is Nothing, "null", site2)
                Try
                    p3 = CType(siteIdPerm1.Union(siteIdPerm2), SiteIdentityPermission)
                    Dim thirdSite As [String] = IIf(p3.Site Is Nothing, "null", p3.Site.ToString())

                    If Not (p3 Is Nothing) Then
                        Console.WriteLine(("The union of " & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & " = " & ControlChars.Lf & ControlChars.Tab & thirdSite & ControlChars.Lf))

                    Else
                        Console.WriteLine(("The union of " & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & " = null." & ControlChars.Lf))
                    End If
                Catch e As Exception
                    ' Expected exception, result of the union is null.
                    Console.WriteLine((e.Message & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & ControlChars.Lf))
                End Try
ContinueWhile2:
            End While
ContinueWhile1:
        End While



        Return returnCodeCode
    End Function 'UnionDemo

    ' Intersect creates and returns a new permission that is the intersection of the 
    ' current permission and the permission specified.
    Private Function IntersectDemo() As Boolean

        Dim returnCodeCode As Boolean = True

        Dim site1 As [String] = ""
        Dim site2 As [String] = ""
        Dim siteIdPerm1, siteIdPerm2, p3 As SiteIdentityPermission

        Dim siteGen1 As New SiteGenerator()
        Dim siteGen2 As New SiteGenerator()

        siteGen1.ResetIndex()
        While siteGen1.CreateSite(site1)
            siteIdPerm1 = siteGen1.CreatePerm(site1)
            If siteIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            siteGen2.ResetIndex()
            Console.WriteLine("**************************************************************************")
            While siteGen2.CreateSite(site2)
                siteIdPerm2 = siteGen2.CreatePerm(site2)
                If siteIdPerm2 Is Nothing Then
                    GoTo ContinueWhile2
                End If
                Dim firstSite As [String] = IIf(site1 Is Nothing, "null", site1)
                Dim secondSite As [String] = IIf(site2 Is Nothing, "null", site2)
                Try
                    p3 = CType(siteIdPerm1.Intersect(siteIdPerm2), SiteIdentityPermission)
                    Dim thirdSite As [String] = IIf(p3.Site Is Nothing, "null", p3.Site.ToString())

                    If Not (p3 Is Nothing) Then
                        Console.WriteLine(("The intersection of " & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & " = " & thirdSite & ControlChars.Lf))

                    Else
                        Console.WriteLine(("The intersection of " & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & " = null." & ControlChars.Lf))
                    End If
                Catch
                    Console.WriteLine(("The intersection of " & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & " = null." & ControlChars.Lf))
                End Try
ContinueWhile2:
            End While
ContinueWhile1:
        End While



        Return returnCodeCode
    End Function 'IntersectDemo

    'Copy creates and returns an identical copy of the current permission.
    Private Function CopyDemo() As Boolean

        Dim returnCodeCode As Boolean = True

        Dim site1 As [String] = ""
        Dim siteIdPerm1, siteIdPerm2 As SiteIdentityPermission

        Dim siteGen1 As New SiteGenerator()
        Dim siteGen2 As New SiteGenerator()

        siteGen1.ResetIndex()
        While siteGen1.CreateSite(site1)
            siteIdPerm1 = siteGen1.CreatePerm(site1)
            If siteIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            siteGen2.ResetIndex()
            Console.WriteLine("**************************************************************************")
            Try
                siteIdPerm2 = CType(siteIdPerm1.Copy(), SiteIdentityPermission)
                If Not (siteIdPerm2 Is Nothing) Then
                    Console.WriteLine(("The copy of " & siteIdPerm2.ToString() & " succeeded." & ControlChars.Lf))
                End If

            Catch e As Exception
                Console.WriteLine(("The copy failed : " & siteIdPerm1.ToString() & e.ToString()))
                GoTo ContinueWhile1
            End Try
ContinueWhile1:
        End While
        Return returnCodeCode
    End Function '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 Function ToFromXmlDemo() As Boolean

        Dim returnCodeCode As Boolean = True

        Dim site1 As [String] = ""
        Dim siteIdPerm1, siteIdPerm2 As SiteIdentityPermission

        Dim siteGen1 As New SiteGenerator()
        Dim siteGen2 As New SiteGenerator()

        siteGen1.ResetIndex()
        While siteGen1.CreateSite(site1)
            siteIdPerm1 = siteGen1.CreatePerm(site1)
            If siteIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            siteGen2.ResetIndex()
            Console.WriteLine("**************************************************************************")
            Try
                siteIdPerm2 = New SiteIdentityPermission(PermissionState.None)
                siteIdPerm2.FromXml(siteIdPerm1.ToXml())
                Dim result As Boolean = siteIdPerm2.Equals(siteIdPerm1)
                If siteIdPerm2.IsSubsetOf(siteIdPerm1) AndAlso siteIdPerm1.IsSubsetOf(siteIdPerm2) Then
                    Console.WriteLine(("Result of ToFromXml = " & siteIdPerm2.ToString()))
                Else
                    Console.WriteLine(siteIdPerm2.ToString())
                    Console.WriteLine(siteIdPerm1.ToString())
                End If
            Catch e As Exception
                Console.WriteLine(("ToFromXml failed. " & e.ToString()))
                GoTo ContinueWhile1
            End Try
ContinueWhile1:
        End While


        Return returnCodeCode
    End Function 'ToFromXmlDemo

    ' Invoke all demos.
    Public Function RunDemo() As Boolean

        Dim returnCode As Boolean = True
        Dim tempReturnCode As Boolean
        ' Call the IsSubsetOf demo.
        tempReturnCode = IsSubsetOfDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("The IsSubsetOf demo completed successfully.")
        Else
            Console.Out.WriteLine("subsetDemo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the Union demo.
        tempReturnCode = UnionDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("The Union demo completed successfully.")
        Else
            Console.Out.WriteLine("UnionDemo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the Intersect demo.  
        tempReturnCode = IntersectDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("The Intersect demo completed successfully.")
        Else
            Console.Out.WriteLine("IntersectDemo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode


        ' Call the Copy demo.   
        tempReturnCode = CopyDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("The Copy demo completed successfully.")
        Else
            Console.Out.WriteLine("CopyDemo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the ToFromXML demo.
        tempReturnCode = ToFromXmlDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("The ToFromXML demo completed successfully.")
        Else
            Console.Out.WriteLine("ToFromXmlDemo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        Return returnCode
    End Function 'RunDemo

    ' Test harness.
    Public Overloads Shared Sub Main(ByVal args() As [String])
        Try
            Dim testcase As New SiteIdentityPermissionDemo()
            Dim returnCode As Boolean = testcase.RunDemo()
            If returnCode Then
                Console.Out.WriteLine("The SiteIdentityPermission demo completed successfully.")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 100
            Else
                Console.Out.WriteLine("The SiteIdentityPermission demo failed.")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 101
            End If
        Catch e As Exception
            Console.Out.WriteLine("The SiteIdentityPermission demo failed.")
            Console.WriteLine(e.ToString())
            Console.Out.WriteLine("Press the Enter key to exit.")
            Dim consoleInput As String = Console.ReadLine()
            System.Environment.ExitCode = 101
        End Try
    End Sub 'Main
End Class 'SiteIdentityPermissionDemo


' This class generates SiteIdentityPermission objects.

Friend Class SiteGenerator

    Private siteArray As String() = {"www.northwindtraders.northwindtraders.com", "*.northwindtraders.com", "*.margiestravel.com", "northwindtraders.com", "*northwindtraders.com", ""}
    '  Replace this array with Web sites of your own choosing.

    Private siteIndex As Integer = 0


    Public Sub New()
        ResetIndex()
    End Sub 'New


    Public Sub ResetIndex()

        siteIndex = 0
    End Sub 'ResetIndex

    ' CreateSite creates a SiteIdentityPermission.
    Public Function CreateSite(ByRef site As String) As Boolean

        If siteIndex >= siteArray.Length Then

            site = "null"
            Return False
        End If
        site = siteArray(siteIndex)
        siteIndex = siteIndex + 1
        Return True
    End Function

    <System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Security", "CA2103")> _
    Public Function CreatePerm(ByRef site As String) As SiteIdentityPermission
        Dim sitePerm As SiteIdentityPermission
        Try
            sitePerm = New SiteIdentityPermission(site)
            Return sitePerm
        Catch e As ArgumentException
            Console.WriteLine(("An ArgumentException was thrown: " & e.Message.ToString()))
            If Not (site Is Nothing) AndAlso site <> "" Then
                Console.WriteLine((site & " is an invalid site."))
            ElseIf site = "" Then
                Console.WriteLine("An empty string signifies an invalid site.")
                site = "an empty string"
            End If
            Return Nothing
        End Try
    End Function 'CreateSite
End Class 'SiteGenerator 

' End of SiteGenerator.
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.
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Runtime::InteropServices;

// This class generates SiteIdentityPermission objects.

[assembly:CLSCompliant(true)];
private ref class SiteGenerator
{
private:
   array<String^>^siteArray;
   int siteIndex;

public:
   SiteGenerator()
   {
      
      //  Replace this array with Web sites of your own choosing.
      array<String^>^temp = {"www.northwindtraders.northwindtraders.com","*.northwindtraders.com","*.margiestravel.com","northwindtraders.com","*northwindtraders.com",""};
      siteArray = temp;
      ResetIndex();
   }

   void ResetIndex()
   {
      siteIndex = 0;
   }

   // CreateSite creates a SiteIdentityPermission.
   bool CreateSite( [Out]interior_ptr<String^> site )
   {
      if ( siteIndex >= siteArray->Length )
      {       
         
          *site = "null";
         return false;
      }

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

    [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute("Microsoft.Security", "CA2103")]
    SiteIdentityPermission^ CreatePerm( [In]interior_ptr<String^> site)
   {
      try
      {
          SiteIdentityPermission^ sitePerm = gcnew SiteIdentityPermission( *site );
          return sitePerm;
      }
      catch ( ArgumentException^ e ) 
      {
         Console::WriteLine( "An ArgumentException was thrown: {0}", e->Message );
         if (  *site != nullptr &&  !( *site)->Equals( "" ) )
         {
            Console::WriteLine( "{0} is an invalid site.",  *site );
         }
         else
         if ( ( *site)->Equals( "" ) )
         {
            Console::WriteLine( "An empty string signifies an invalid site." );
             *site = "an empty string";
         }

         return nullptr;
      }

   }
};


// End of SiteGenerator.
public ref class SiteIdentityPermissionDemo
{
private:

   // IsSubsetOf determines whether the current permission is a subset of the specified permission.
   bool IsSubsetOfDemo()
   {
      bool returnCodeCode = true;
      String^ site1;
      String^ site2;

      SiteIdentityPermission^ siteIdPerm1;
      SiteIdentityPermission^ siteIdPerm2;
      SiteGenerator^ siteGen1 = gcnew SiteGenerator;
      SiteGenerator^ siteGen2 = gcnew SiteGenerator;
      siteGen1->ResetIndex();
      while ( siteGen1->CreateSite( &site1 ) )
      {
         siteIdPerm1 = siteGen1->CreatePerm(&site1);
         if ( siteIdPerm1 == nullptr )
                  continue;

         siteGen2->ResetIndex();
         Console::WriteLine( "**************************************************************************" );
         while ( siteGen2->CreateSite(  &site2 ) )
         {
             siteIdPerm2 = siteGen1->CreatePerm(&site2);
            try
            {
               if ( siteIdPerm2 == nullptr )
                              continue;
               if ( siteIdPerm1->IsSubsetOf( siteIdPerm2 ) )
               {
                  Console::WriteLine( "{0} is a subset of {1}", site1, site2 );
               }
               else
               {
                  Console::WriteLine( "{0} is not a subset of {1}", site1, site2 );
               }
            }
            catch ( Exception^ e ) 
            {
               Console::WriteLine( "An exception was thrown : {0}", e );
               return false;
            }

         }
      }

      return returnCodeCode;
   }


   // Union creates a new permission that is the union of the current permission
   // and the specified permission.
   bool UnionDemo()
   {
      bool returnCodeCode = true;
      String^ site1;
      String^ site2;

      SiteIdentityPermission^ siteIdPerm1;
      SiteIdentityPermission^ siteIdPerm2;
      SiteIdentityPermission^ p3;
      SiteGenerator^ siteGen1 = gcnew SiteGenerator;
      SiteGenerator^ siteGen2 = gcnew SiteGenerator;
      siteGen1->ResetIndex();
      while ( siteGen1->CreateSite( &site1 ) )
      {
         siteIdPerm1 = siteGen1->CreatePerm(&site1);
         if ( siteIdPerm1 == nullptr  )
                  continue;

         siteGen2->ResetIndex();
         Console::WriteLine( "**************************************************************************" );
         while ( siteGen2->CreateSite( &site2 ) )
         {
            siteIdPerm2 = siteGen2->CreatePerm(&site2);
            if ( siteIdPerm2 == nullptr  )
                        continue;
            String^ firstSite = site1 == nullptr ? "null" : site1;
            String^ secondSite = site2 == nullptr ? "null" : site2;
            try
            {
               p3 = dynamic_cast<SiteIdentityPermission^>(siteIdPerm1->Union( siteIdPerm2 ));
               String^ thirdSite = p3->Site == nullptr ? "null" : p3->Site;
               if ( p3 != nullptr )
               {
                  Console::WriteLine( "The union of {0} and \n\t{1} = \n\t{2}\n", firstSite, secondSite, thirdSite );
               }
               else
               {
                  Console::WriteLine( "The union of {0} and \n\t{1} = null.\n", firstSite, secondSite );
               }
            }
            catch ( Exception^ ) 
            {
               
               // Expected exception, result of the union is 0.
               Console::WriteLine( "The union of {0} and \n\t{1} = null.\n", firstSite, secondSite );
            }

         }
      }

      return returnCodeCode;
   }


   // Intersect creates and returns a new permission that is the intersection of the
   // current permission and the permission specified.
   bool IntersectDemo()
   {
      bool returnCodeCode = true;
      String^ site1;
      String^ site2;

      SiteIdentityPermission^ siteIdPerm1;
      SiteIdentityPermission^ siteIdPerm2;
      SiteIdentityPermission^ p3;
      SiteGenerator^ siteGen1 = gcnew SiteGenerator;
      SiteGenerator^ siteGen2 = gcnew SiteGenerator;
      siteGen1->ResetIndex();
      while ( siteGen1->CreateSite(  &site1 ) )
      {
          siteIdPerm1 = siteGen1->CreatePerm(&site1);
         if ( siteIdPerm1 == nullptr  )
                  continue;

         siteGen2->ResetIndex();
         Console::WriteLine( "**************************************************************************" );
         while ( siteGen2->CreateSite(  &site2 ) )
         {
             siteIdPerm2 = siteGen2->CreatePerm(&site2);
            if ( siteIdPerm2 == nullptr )
                        continue;
            String^ firstSite = site1 == nullptr ? "0" : site1;
            String^ secondSite = site2 == nullptr ? "0" : site2;
            try
            {
               p3 = dynamic_cast<SiteIdentityPermission^>(siteIdPerm1->Intersect( siteIdPerm2 ));
               String^ thirdSite = p3->Site == nullptr ? "0" : p3->Site;
               if ( p3 != nullptr )
               {
                  Console::WriteLine( "The intersection of {0} and \n\t{1} = {2}\n", firstSite, secondSite, thirdSite );
               }
               else
               {
                  Console::WriteLine( "The intersection of {0} and \n\t{1} = null.\n", firstSite, secondSite );
               }
            }
            catch ( Exception^ ) 
            {
               Console::WriteLine( "The intersection of {0} and \n\t{1} = null.\n", firstSite, secondSite );
            }

         }
      }

      return returnCodeCode;
   }


   //Copy creates and returns an identical copy of the current permission.
   bool CopyDemo()
   {
      bool returnCodeCode = true;
      String^ site1;
      SiteIdentityPermission^ siteIdPerm1;
      SiteIdentityPermission^ siteIdPerm2;

      SiteGenerator^ siteGen1 = gcnew SiteGenerator;
      SiteGenerator^ siteGen2 = gcnew SiteGenerator;
      siteGen1->ResetIndex();
      while ( siteGen1->CreateSite(  &site1  ) )
      {
         siteIdPerm1 = siteGen1->CreatePerm(&site1);
         if ( siteIdPerm1 == nullptr  )
                  continue;

         siteGen2->ResetIndex();
         Console::WriteLine( "**************************************************************************" );
         try
         {
            siteIdPerm2 = dynamic_cast<SiteIdentityPermission^>(siteIdPerm1->Copy());
            if ( siteIdPerm2 != nullptr )
            {
               Console::WriteLine( "The copy of {0} succeeded.\n", siteIdPerm2 );
            }
         }
         catch ( Exception^ e ) 
         {
            Console::WriteLine( "The copy failed : {0}{1}", siteIdPerm1, 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.
   bool ToFromXmlDemo()
   {
      bool returnCodeCode = true;
      String^ site1;
      SiteIdentityPermission^ siteIdPerm1;
      SiteIdentityPermission^ siteIdPerm2;

      SiteGenerator^ siteGen1 = gcnew SiteGenerator;
      SiteGenerator^ siteGen2 = gcnew SiteGenerator;
      siteGen1->ResetIndex();
      while ( siteGen1->CreateSite( &site1  ) )
      {
         siteIdPerm1 = siteGen1->CreatePerm(&site1);
         if ( siteIdPerm1 == nullptr  )
                  continue;

         siteGen2->ResetIndex();
         Console::WriteLine( "**************************************************************************" );
         try
         {
            siteIdPerm2 = gcnew SiteIdentityPermission( PermissionState::None );
            siteIdPerm2->FromXml( siteIdPerm1->ToXml() );
            bool result = siteIdPerm2->Equals( siteIdPerm1 );
            if ( siteIdPerm2->IsSubsetOf( siteIdPerm1 ) && siteIdPerm1->IsSubsetOf( siteIdPerm2 ) )
            {
               Console::WriteLine( "Result of ToFromXml = {0}", siteIdPerm2 );
            }
            else
            {
               Console::WriteLine( siteIdPerm2 );
               Console::WriteLine( siteIdPerm1 );
            }
         }
         catch ( Exception^ e ) 
         {
            Console::WriteLine( "ToFromXml failed. {0}", e );
            continue;
         }

      }

      return returnCodeCode;
   }


public:

   // Invoke all demos.
   bool RunDemo()
   {
      bool returnCode = true;
      bool tempReturnCode;
      
      // Call the IsSubsetOf demo.
      if ( tempReturnCode = IsSubsetOfDemo() )
            Console::WriteLine( "The IsSubsetOf demo completed successfully." );
      else
            Console::WriteLine( "subsetDemo failed." );

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

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

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

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

      returnCode = tempReturnCode && returnCode;
      return (returnCode);
   }

};


// Test harness.
int main()
{
   try
   {
      SiteIdentityPermissionDemo^ testcase = gcnew SiteIdentityPermissionDemo;
      bool returnCode = testcase->RunDemo();
      if ( returnCode )
      {
         Console::WriteLine( "The SiteIdentityPermission demo completed successfully." );
         Console::WriteLine( "Press the Enter key to exit." );
         Console::ReadLine();
         System::Environment::ExitCode = 100;
      }
      else
      {
         Console::WriteLine( "The SiteIdentityPermission demo failed." );
         Console::WriteLine( "Press the Enter key to exit." );
         Console::ReadLine();
         System::Environment::ExitCode = 101;
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The SiteIdentityPermission demo failed." );
      Console::WriteLine( e );
      Console::WriteLine( "Press the Enter key to exit." );
      Console::ReadLine();
      System::Environment::ExitCode = 101;
   }

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

Vererbungshierarchie

System.Object
   System.Security.CodeAccessPermission
    System.Security.Permissions.SiteIdentityPermission

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

SiteIdentityPermission-Member
System.Security.Permissions-Namespace
SiteIdentityPermissionAttribute
Site
SiteMembershipCondition

Weitere Ressourcen

Sicherheitsberechtigungen
Anfordern von Berechtigungen