Export (0) Print
Expand All

WebPermission.ToXml Method

Creates an XML encoding of a WebPermission and its current state.

[Visual Basic]
Overrides Public Function ToXml() As SecurityElement Implements _
   ISecurityEncodable.ToXml
[C#]
public override SecurityElement ToXml();
[C++]
public: SecurityElement* ToXml();
[JScript]
public override function ToXml() : SecurityElement;

Return Value

A SecurityElement containing an XML-encoded representation of the WebPermission, including state information.

Implements

ISecurityEncodable.ToXml

Remarks

Use the FromXml method to restore the state information from a SecurityElement.

Example

[Visual Basic, C#, C++] The following example demonstrates how to use ToXml to create a System.Security.SecurityElement and print its attributes to the console.

[Visual Basic] 
' Create  a WebPermission without permission on the protected resource.
Dim myWebPermission1 As New WebPermission(PermissionState.None)

' Create a SecurityElement by calling the ToXml method on the WebPermission 
' instance and display its attributes (which hold the XML encoding of 
' the WebPermission).
Console.WriteLine("Attributes and Values of the WebPermission are :")
myWebPermission1.ToXml().ToString()

' Create another WebPermission with no permission on the protected resource.
Dim myWebPermission2 As New WebPermission(PermissionState.None)

'Converts the new WebPermission from XML using myWebPermission1.
myWebPermission2.FromXml(myWebPermission1.ToXml())


[C#] 

    // Create  a WebPermission without permission on the protected resource.
    WebPermission myWebPermission1 = new WebPermission(PermissionState.None);

    // Create a SecurityElement by calling the ToXml method on the WebPermission 
    // instance and display its attributes (which hold the XML encoding of 
    // the WebPermission).
    Console.WriteLine("Attributes and Values of the WebPermission are :");
    myWebPermission1.ToXml().ToString();

    // Create another WebPermission with no permission on the protected resource.
    WebPermission myWebPermission2 = new WebPermission(PermissionState.None);

    //Converts the new WebPermission from XML using myWebPermission1.
    myWebPermission2.FromXml(myWebPermission1.ToXml());


[C++] 
// Create  a WebPermission without permission on the protected resource
   WebPermission* myWebPermission1 =
   new WebPermission(PermissionState::None);

// Create a SecurityElement by calling the ToXml method on the WebPermission
// instance and display its attributes (which hold the XML encoding of
// the WebPermission).
Console::WriteLine(S"Attributes and Values of the WebPermission are :");
myWebPermission1->ToXml();

// Create another WebPermission with no permission on the protected resource
   WebPermission* myWebPermission2 =
   new WebPermission(PermissionState::None);

//Converts the new WebPermission from XML using myWebPermission1.
myWebPermission2->FromXml(myWebPermission1->ToXml());

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

WebPermission Class | WebPermission Members | System.Net Namespace | FromXml

Show:
© 2014 Microsoft