Freigeben über


UrlIdentityPermission.ToXml-Methode

Erstellt eine XML-Codierung der Berechtigung und ihres aktuellen Zustands.

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

Syntax

'Declaration
Public Overrides Function ToXml As SecurityElement
'Usage
Dim instance As UrlIdentityPermission
Dim returnValue As SecurityElement

returnValue = instance.ToXml
public override SecurityElement ToXml ()
public:
virtual SecurityElement^ ToXml () override
public SecurityElement ToXml ()
public override function ToXml () : SecurityElement

Rückgabewert

Eine XML-Codierung der Berechtigung, einschließlich der Zustandsinformationen.

Beispiel

    ' 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 returnValue As Boolean = True

        Dim url1 As String = ""
        Dim urlIdPerm1, urlIdPerm2 As UrlIdentityPermission

        Dim urlGen1 As New UrlGenerator()
        Dim urlGen2 As New UrlGenerator()

        urlGen1.ResetIndex()
        While urlGen1.CreateUrl(url1)
            urlIdPerm1 = New UrlIdentityPermission(url1)
            Console.WriteLine("********************************************************\n")
            urlGen2.ResetIndex()
            Try
                urlIdPerm2 = New UrlIdentityPermission(PermissionState.None)
                urlIdPerm2.FromXml(urlIdPerm1.ToXml())
                Console.WriteLine("Result of ToFromXml = " & urlIdPerm2.ToString())

            Catch e As Exception
                Console.WriteLine("ToFromXml failed :" & urlIdPerm1.ToString() & e.ToString())
                GoTo ContinueWhile1
            End Try
ContinueWhile1:
        End While

        Return returnValue
    End Function 'ToFromXmlDemo
// ToXml creates an XML encoding of the permission and its current state; FromXml
// reconstructs a permission with the specified state from the XML encoding.
private bool ToFromXmlDemo()
{

    bool returnValue = true;

    string url1;
    UrlIdentityPermission urlIdPerm1, urlIdPerm2;

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

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

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

    return returnValue;

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

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

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

UrlIdentityPermission-Klasse
UrlIdentityPermission-Member
System.Security.Permissions-Namespace