次の方法で共有


UrlIdentityPermission.ToXml メソッド

アクセス許可とその現在の状態を表す XML エンコーディングを作成します。

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

戻り値

状態情報を含む、アクセス許可の XML エンコーディング。

実装

ISecurityEncodable.ToXml

使用例

 
' 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(urlIdPerm1, url1)
        If urlIdPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        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


[C#] 
// 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 urlIdPerm1, out url1)) 
        {
            if(urlIdPerm1 == null) continue;
            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;

    }

[C++] 
// 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(&urlIdPerm1, &url1)) {
      if (urlIdPerm1 == 0) continue;
      Console::WriteLine(S"********************************************************\n");
      urlGen2->ResetIndex();
      try {
         urlIdPerm2 = new UrlIdentityPermission(PermissionState::None);
         urlIdPerm2->FromXml(urlIdPerm1->ToXml());
         Console::WriteLine(S"Result of ToFromXml = {0}\n", urlIdPerm2);
      } catch (Exception* e) {
         Console::WriteLine(S"ToFromXml failed : {0}{1}", urlIdPerm1, e);
         continue;
      }
   }
   return returnValue;
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

UrlIdentityPermission クラス | UrlIdentityPermission メンバ | System.Security.Permissions 名前空間