This documentation is archived and is not being maintained.

UrlIdentityPermission.ToXml Method

Creates an XML encoding of the permission and its current state.

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

public override SecurityElement ToXml ()
public SecurityElement ToXml ()
public override function ToXml () : SecurityElement

Return Value

An XML encoding of the permission, including any state information.

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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: