MessageQueuePermission MessageQueuePermission MessageQueuePermission MessageQueuePermission Class

定義

允許控制訊息處理的程式碼存取使用權限。Allows control of code access permissions for messaging.

public ref class MessageQueuePermission sealed : System::Security::CodeAccessPermission, System::Security::Permissions::IUnrestrictedPermission
[System.Serializable]
public sealed class MessageQueuePermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
type MessageQueuePermission = class
    inherit CodeAccessPermission
    interface IUnrestrictedPermission
Public NotInheritable Class MessageQueuePermission
Inherits CodeAccessPermission
Implements IUnrestrictedPermission
繼承
MessageQueuePermissionMessageQueuePermissionMessageQueuePermissionMessageQueuePermission
屬性
實作

範例

下列程式碼範例會建立的MessageQueuePermission多個實例,並示範PermissionEntries屬性的用法。The following code example creates several instances of MessageQueuePermission and demonstrates the use of the PermissionEntries property.


using System;
using System.Messaging;

public class MessageQueuePermissionExample
{
    public static void Main()
    {
        // Create a new instance of the class.
        MessageQueuePermissionExample example =
            new MessageQueuePermissionExample();

        // Create a message queue on the local computer.
        CreateQueue(".\\exampleQueue", false);

        // Demonstrate MessageQueuePermission's constructors.
        example.CreatePermission1();
        example.CreatePermission2();
        example.CreatePermission3();
        example.CreatePermission4();
        example.CreatePermission5();

        // Get and set MessageQueuePermission's PermissionEntries property.
        example.GetPermissionEntries();
    }

    // Creates a new queue.
    public static void CreateQueue(string queuePath, bool transactional)
    {
        if(!MessageQueue.Exists(queuePath))
        {
            MessageQueue.Create(queuePath, transactional);
        }
        else
        {
            Console.WriteLine(queuePath + " already exists.");
        }
    }

    // Demonstrates the following MessageQueuePermission constructor:
    // public #ctor ()
    public void CreatePermission1()
    {
        // Create a new instance of MessageQueuePermission.
        MessageQueuePermission permission = new MessageQueuePermission();
    }

    // Demonstrates the following MessageQueuePermission constructor:
    // public #ctor (MessageQueuePermissionAccess permissionAccess,
    //  String path)
    public void CreatePermission2()
    {
        // Create a new instance of MessageQueuePermission.
        MessageQueuePermission permission = new MessageQueuePermission(
            MessageQueuePermissionAccess.Receive,
            ".\\exampleQueue");
    }

    // Demonstrates the following MessageQueuePermission constructor:
    // public #ctor (MessageQueuePermissionAccess permissionAccess,
    //  String machineName, String label, String category)
    public void CreatePermission3()
    {
        // Connect to a queue on the local computer.
        MessageQueue queue = new MessageQueue(".\\exampleQueue");

        // Create a new instance of MessageQueuePermission.
    string queueCategory = queue.Category.ToString();
    string machineName = queue.MachineName;
    string label = queue.Label;
        MessageQueuePermission permission = new MessageQueuePermission(
            MessageQueuePermissionAccess.Receive,
            machineName,
            label,
            queueCategory);
    }

    // Demonstrates the following MessageQueuePermission constructor:
    //public #ctor (MessageQueuePermissionEntry[] permissionAccessEntries)
    public void CreatePermission4()
    {
        // Connect to a queue on the local computer.
        MessageQueue queue = new MessageQueue(".\\exampleQueue");

        // Create an array of type MessageQueuePermissionEntry.
        MessageQueuePermissionEntry[] entries =
            new MessageQueuePermissionEntry[1];

        // Create a new instance of MessageQueuePermissionEntry and place the
        // instance in the array.
    string machineName = queue.MachineName;
    string label = queue.Label;
        entries[0] = new MessageQueuePermissionEntry(
            MessageQueuePermissionAccess.Receive,
            machineName,
            label,
            queue.Category.ToString());

        // Create a new instance of MessageQueuePermission.
        MessageQueuePermission permission = new MessageQueuePermission(
            entries);
    }

    // Demonstrates the following MessageQueuePermission constructor:
    //public #ctor (PermissionState state)
    public void CreatePermission5()
    {
        // Create a new instance of MessageQueuePermission.
        MessageQueuePermission permission = new MessageQueuePermission(
            System.Security.Permissions.PermissionState.Unrestricted);
    }

    public void GetPermissionEntries()
    {
    
        // Connect to a queue on the local computer.
        MessageQueue queue = new MessageQueue(".\\exampleQueue");

        // Create an array of type MessageQueuePermissionEntry.
        MessageQueuePermissionEntry[] entries =
            new MessageQueuePermissionEntry[1];

        // Create a new instance of MessageQueuePermissionEntry and place the
        // instance in the array.
    string machineName = queue.MachineName;
    string label = queue.Label;
        entries[0] = new MessageQueuePermissionEntry(
            MessageQueuePermissionAccess.Receive,
            machineName,
            label,
            queue.Category.ToString());

        // Create a new instance of MessageQueuePermission.
        MessageQueuePermission permission = new MessageQueuePermission(
            entries);

        // Create a new instance of MessageQueuePermissionEntryCollection and
        // use it to retrieve the permission's PermissionEntries property
        // value.
        MessageQueuePermissionEntryCollection collection =
            permission.PermissionEntries;

        // Loop through the collection.
        foreach(MessageQueuePermissionEntry entry in collection)
        {
            // Display the property values of each MessageQueuePermissionEntry.
            Console.WriteLine("PermissionAccess: {0}", entry.PermissionAccess);
            Console.WriteLine("MachineName: {0}", entry.MachineName);
            Console.WriteLine("Label: {0}", entry.Label);
            Console.WriteLine("Category: {0}", entry.Category.ToString());
        }
    }
}

建構函式

MessageQueuePermission() MessageQueuePermission() MessageQueuePermission() MessageQueuePermission()

初始化 MessageQueuePermission 類別的新執行個體。Initializes a new instance of the MessageQueuePermission class.

MessageQueuePermission(MessageQueuePermissionAccess, String) MessageQueuePermission(MessageQueuePermissionAccess, String) MessageQueuePermission(MessageQueuePermissionAccess, String) MessageQueuePermission(MessageQueuePermissionAccess, String)

使用指定的存取等級和佇列路徑,初始化 MessageQueuePermission 類別的新執行個體。Initializes a new instance of the MessageQueuePermission class with the specified access levels and the path of the queue.

MessageQueuePermission(MessageQueuePermissionAccess, String, String, String) MessageQueuePermission(MessageQueuePermissionAccess, String, String, String) MessageQueuePermission(MessageQueuePermissionAccess, String, String, String) MessageQueuePermission(MessageQueuePermissionAccess, String, String, String)

使用指定的存取等級、要使用的電腦、佇列描述和佇列分類,初始化 MessageQueuePermission 類別的新執行個體。Initializes a new instance of the MessageQueuePermission class with the specified access levels, computer to use, queue description, and queue category.

MessageQueuePermission(MessageQueuePermissionEntry[]) MessageQueuePermission(MessageQueuePermissionEntry[]) MessageQueuePermission(MessageQueuePermissionEntry[]) MessageQueuePermission(MessageQueuePermissionEntry[])

使用指定的使用權限存取等級項目,初始化 MessageQueuePermission 類別的新執行個體。Initializes a new instance of the MessageQueuePermission class with the specified permission access level entries.

MessageQueuePermission(PermissionState) MessageQueuePermission(PermissionState) MessageQueuePermission(PermissionState) MessageQueuePermission(PermissionState)

使用指定的使用權限狀態,初始化 MessageQueuePermission 類別的新執行個體。Initializes a new instance of the MessageQueuePermission class with the specified permission state.

屬性

PermissionEntries PermissionEntries PermissionEntries PermissionEntries

取得這個使用權限要求的使用權限項目的集合。Gets the collection of permission entries for this permissions request.

方法

Assert() Assert() Assert() Assert()

宣告即使堆疊中較高層的呼叫端未獲得資源存取權限,呼叫程式碼仍可透過呼叫這個方法的程式碼要求權限,來存取受保護的資源。Declares that the calling code can access the resource protected by a permission demand through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource. 使用 Assert() 可能會造成安全性問題。Using Assert() can create security issues.

(Inherited from CodeAccessPermission)
Copy() Copy() Copy() Copy()

建立並傳回目前使用權限物件的相同複本。Creates and returns an identical copy of the current permission object.

Demand() Demand() Demand() Demand()

如果呼叫堆疊中所有較高層的呼叫端尚未授與目前執行個體 (Instance) 所指定的使用權限,請於執行階段強制執行 SecurityExceptionForces a SecurityException at run time if all callers higher in the call stack have not been granted the permission specified by the current instance.

(Inherited from CodeAccessPermission)
Deny() Deny() Deny() Deny()

防止呼叫堆疊中較高層的呼叫端,使用呼叫這個方法的程式碼來存取目前執行個體所指定的資源。Prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.

(Inherited from CodeAccessPermission)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的 CodeAccessPermission 物件是否等於目前的 CodeAccessPermissionDetermines whether the specified CodeAccessPermission object is equal to the current CodeAccessPermission.

(Inherited from CodeAccessPermission)
FromXml(SecurityElement) FromXml(SecurityElement) FromXml(SecurityElement) FromXml(SecurityElement)

透過 XML 編碼,重新建構具有指定狀態的安全性物件。Reconstructs a security object with a specified state from an XML encoding.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

取得 CodeAccessPermission 物件的雜湊碼,其適合用於雜湊表這類的雜湊演算法和資料結構。Gets a hash code for the CodeAccessPermission object that is suitable for use in hashing algorithms and data structures such as a hash table.

(Inherited from CodeAccessPermission)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
Intersect(IPermission) Intersect(IPermission) Intersect(IPermission) Intersect(IPermission)

傳回新使用權限物件,表示目前使用權限物件和指定使用權限物件的交集。Returns a new permission object that represents the intersection of the current permission object and the specified permission object.

IsSubsetOf(IPermission) IsSubsetOf(IPermission) IsSubsetOf(IPermission) IsSubsetOf(IPermission)

傳回值,指出目前的使用權限物件是否為指定使用權限物件的子集。Returns a value that indicates whether the current permission object is a subset of the specified permission object.

IsUnrestricted() IsUnrestricted() IsUnrestricted() IsUnrestricted()

傳回值,指出使用權限是否可以表示為不暸解使用權限語意 (Semantics) 而不受限制。Returns a value that indicates whether the permission can be represented as unrestricted without any knowledge of the permission semantics.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
PermitOnly() PermitOnly() PermitOnly() PermitOnly()

防止呼叫堆疊中較高層的呼叫端,使用呼叫這個方法的程式碼來存取除了目前執行個體所指定資源之外的所有資源。Prevents callers higher in the call stack from using the code that calls this method to access all resources except for the resource specified by the current instance.

(Inherited from CodeAccessPermission)
ToString() ToString() ToString() ToString()

建立並傳回目前使用權限物件的字串表示。Creates and returns a string representation of the current permission object.

(Inherited from CodeAccessPermission)
ToXml() ToXml() ToXml() ToXml()

建立安全物件及其目前狀態的 XML 編碼方式。Creates an XML encoding of the security object and its current state.

Union(IPermission) Union(IPermission) Union(IPermission) Union(IPermission)

傳回新的使用權限物件,這個物件是目前和指定使用權限物件的聯集。Returns a new permission object that is the union of the current and specified permission objects.

明確介面實作

IPermission.Demand() IPermission.Demand() IPermission.Demand() IPermission.Demand() Inherited from CodeAccessPermission
IStackWalk.Assert() IStackWalk.Assert() IStackWalk.Assert() IStackWalk.Assert() Inherited from CodeAccessPermission
IStackWalk.Demand() IStackWalk.Demand() IStackWalk.Demand() IStackWalk.Demand() Inherited from CodeAccessPermission
IStackWalk.Deny() IStackWalk.Deny() IStackWalk.Deny() IStackWalk.Deny() Inherited from CodeAccessPermission
IStackWalk.PermitOnly() IStackWalk.PermitOnly() IStackWalk.PermitOnly() IStackWalk.PermitOnly() Inherited from CodeAccessPermission

適用於

另請參閱