다음을 통해 공유


SiteIdentityPermission 클래스

코드가 발생되는 웹 사이트의 ID 권한을 정의합니다. 이 클래스는 상속될 수 없습니다.

네임스페이스: System.Security.Permissions
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class SiteIdentityPermission
    Inherits CodeAccessPermission
‘사용 방법
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

설명

이 클래스를 사용하면 특정 웹 사이트의 호출자를 확인할 수 있습니다. 사이트 ID는 HTTP, HTTPS 및 FTP 프로토콜을 사용하는 URL의 코드에 대해서만 정의됩니다. 사이트는 URL의 프로토콜 다음에 오는 "//"와 그 뒤에 있는"/"(있을 경우) 사이의 문자열입니다. 예를 들어 https://www.fourthcoffee.com/process/grind.htm이라는 URL에서 사이트는 www.fourthcoffee.com입니다. 여기에서 포트 번호는 제외됩니다. 지정된 URL이 https://www.fourthcoffee.com:8000/인 경우 사이트는 www.fourthcoffee.com:8000이 아니라 www.fourthcoffee.com입니다.

사이트를 정확하게 일치시키거나 점 구분 기호 앞에 와일드카드("*")를 사용할 수 있습니다. 예를 들어 사이트 이름 문자열 *.fourthcoffee.com은 fourthcoffee.com 및 www.fourthcoffee.com과 일치합니다. 와일드카드를 사용하지 않는 경우에는 사이트 이름이 정확하게 일치해야 합니다. 사이트 이름 문자열 *는 모든 사이트와 일치하지만 사이트 증명이 없는 코드와는 일치하지 않습니다.

경고

SiteIdentityPermission은 URL과 IP 주소를 포함하여 사이트의 모든 경로에 대한 사용 권한을 부여합니다. 사이트에 대한 액세스를 Deny하려면 해당 사이트에 대해 가능한 모든 경로를 Deny해야 합니다. 예를 들어 www.fourthcoffee.com의 IP 주소가 192.168.238.241인 경우 www.fourthcoffee.com에 대한 액세스를 Deny하려면 www.fourthcoffee.com, 192.168.238.241 및 사이트에 액세스할 수 있는 그 밖의 모든 경로를 Deny해야 합니다. 경로가 여러 개인 경우 PermitOnlyDeny를 함께 사용하는 것이 좋습니다. 이 주제 및 Deny와 함께 PermitOnly를 사용하는 방법에 대한 자세한 내용은 Deny 메서드 사용 항목의 Canonicalization Problems Using Deny를 참조하십시오.

참고

.NET Framework 버전 1.0 및 1.1에서 ID 권한은 Unrestricted 권한 상태 값을 가질 수 없습니다. .NET Framework 버전 2.0에서 ID 권한은 모든 권한 상태 값을 가질 수 있습니다. 즉, 버전 2.0에서 ID 권한의 동작은 IUnrestrictedPermission 인터페이스를 구현하는 권한의 동작과 같습니다. 버전 1.1 CAS 정책을 사용하여 버전 2.0 응용 프로그램을 실행하는 데 대한 자세한 내용은 <legacyV1CASPolicy> 요소를 참조하십시오.

예제

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

상속 계층 구조

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

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

SiteIdentityPermission 멤버
System.Security.Permissions 네임스페이스
SiteIdentityPermissionAttribute
Site
SiteMembershipCondition

기타 리소스

보안 권한
권한 요청