MessageQueuePermissionAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
允许进行声明 MessageQueue 权限检查。
public ref class MessageQueuePermissionAttribute : System::Security::Permissions::CodeAccessSecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Serializable]
public class MessageQueuePermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Serializable>]
type MessageQueuePermissionAttribute = class
inherit CodeAccessSecurityAttribute
Public Class MessageQueuePermissionAttribute
Inherits CodeAccessSecurityAttribute
- 继承
- 属性
示例
以下代码示例演示了 MessageQueuePermissionAttribute 的用法。
#using <System.Messaging.dll>
#using <System.dll>
using namespace System;
using namespace System::Messaging;
// Creates a new queue.
void CreateQueue(String^ queuePath, bool transactional)
{
if (!MessageQueue::Exists(queuePath))
{
MessageQueue^ queue = MessageQueue::Create(queuePath, transactional);
queue->Close();
}
else
{
Console::WriteLine("{0} already exists.", queuePath);
}
}
// Demonstrates the following MessageQueuePermissionAttribute constructor:
// public #ctor (SecurityAction action)
void CreateAttribute()
{
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute^ attribute =
gcnew MessageQueuePermissionAttribute(
System::Security::Permissions::SecurityAction::Assert);
}
void CategoryExample()
{
// Connect to a queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute^ attribute =
gcnew MessageQueuePermissionAttribute(
System::Security::Permissions::SecurityAction::Assert);
// Set the attribute's Category property value, based on the queue's
// Category property value.
attribute->Category = queue->Category.ToString();
// Display the new value of the attribute's Category property.
Console::WriteLine("attribute->Category: {0}",
attribute->Category);
queue->Close();
}
void LabelExample()
{
// Connect to a queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute^ attribute =
gcnew MessageQueuePermissionAttribute(
System::Security::Permissions::SecurityAction::Assert);
// Set the attribute's Label property value, based on the queue's Label
// property value.
attribute->Label = queue->Label;
// Display the new value of the attribute's Label property.
Console::WriteLine("attribute->Label: {0}", attribute->Label);
queue->Close();
}
void MachineNameExample()
{
// Connect to a queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute^ attribute =
gcnew MessageQueuePermissionAttribute(
System::Security::Permissions::SecurityAction::Assert);
// Set the attribute's MachineName property value, based on the queue's
// MachineName property value.
attribute->MachineName = queue->MachineName;
// Display the new value of the attribute's MachineName property.
Console::WriteLine("attribute->MachineName: {0}",
attribute->MachineName);
queue->Close();
}
void PathExample()
{
// Connect to a queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute^ attribute =
gcnew MessageQueuePermissionAttribute(
System::Security::Permissions::SecurityAction::Assert);
// Set the attribute's Path property value, based on the queue's Path
// property value.
attribute->Path = queue->Path;
// Display the new value of the attribute's Path property.
Console::WriteLine("attribute->Path: {0}", attribute->Path);
queue->Close();
}
void PermissionAccessExample()
{
// Connect to a queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute^ attribute =
gcnew MessageQueuePermissionAttribute(
System::Security::Permissions::SecurityAction::Assert);
// Set the attribute's PermissionAccess property value.
attribute->PermissionAccess = MessageQueuePermissionAccess::Receive;
// Display the new value of the attribute's PermissionAccess property.
Console::WriteLine("attribute->PermissionAccess: {0}",
attribute->PermissionAccess);
queue->Close();
}
void CreatePermissionExample()
{
// Connect to a queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute^ attribute =
gcnew MessageQueuePermissionAttribute(
System::Security::Permissions::SecurityAction::Assert);
// Set the attribute's Path property value, based on the queue's Path
// property value.
attribute->Path = queue->Path;
// Get an IPermission interface by calling the attribute's
// CreatePermission() method.
System::Security::IPermission^ permission = attribute->CreatePermission();
queue->Close();
}
int main()
{
try
{
// Create a non-transactional queue on the local computer.
CreateQueue(".\\exampleQueue", false);
// Demonstrate the members of MessageQueuePermissionAttribute.
// Note that the Path, FormatName, MachineName, Label, and Category
// property values cannot all be set on the same instance of
// MessageQueuePermissionAttribute. Trying to do so will throw an
// exception of type System.InvalidOperationException.
CreateAttribute();
CategoryExample();
LabelExample();
MachineNameExample();
PathExample();
PermissionAccessExample();
CreatePermissionExample();
}
catch (InvalidOperationException^)
{
Console::WriteLine("Please install Message Queuing.");
}
catch (MessageQueueException^ ex)
{
Console::WriteLine(ex->Message);
}
}
using System;
using System.Messaging;
public class MessageQueuePermissionAttributeExample
{
public static void Main()
{
// Create a new instance of the class.
MessageQueuePermissionAttributeExample example =
new MessageQueuePermissionAttributeExample();
// Create a non-transactional queue on the local computer.
CreateQueue(".\\exampleQueue", false);
// Demonstrate the members of MessageQueuePermissionAttribute.
// Note that the Path, FormatName, MachineName, Label, and Category
// property values cannot all be set on the same instance of
// MessageQueuePermissionAttribute. Trying to do so will throw an
// exception of type System.InvalidOperationException.
example.CreateAttribute();
example.CategoryExample();
example.LabelExample();
example.MachineNameExample();
example.PathExample();
example.PermissionAccessExample();
example.CreatePermissionExample();
}
// 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 MessageQueuePermissionAttribute constructor:
// public #ctor (SecurityAction action)
public void CreateAttribute()
{
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute attribute =
new MessageQueuePermissionAttribute(
System.Security.Permissions.SecurityAction.Assert);
}
public void CategoryExample()
{
// Connect to a queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute attribute =
new MessageQueuePermissionAttribute(
System.Security.Permissions.SecurityAction.Assert);
// Set the attribute's Category property value, based on the queue's
// Category property value.
attribute.Category = queue.Category.ToString();
// Display the new value of the attribute's Category property.
Console.WriteLine("attribute.Category: {0}",
attribute.Category.ToString());
}
public void LabelExample()
{
// Connect to a queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute attribute =
new MessageQueuePermissionAttribute(
System.Security.Permissions.SecurityAction.Assert);
// Set the attribute's Label property value, based on the queue's Label
// property value.
attribute.Label = queue.Label;
// Display the new value of the attribute's Label property.
Console.WriteLine("attribute.Label: {0}", attribute.Label);
}
public void MachineNameExample()
{
// Connect to a queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute attribute =
new MessageQueuePermissionAttribute(
System.Security.Permissions.SecurityAction.Assert);
// Set the attribute's MachineName property value, based on the queue's
// MachineName property value.
attribute.MachineName = queue.MachineName;
// Display the new value of the attribute's MachineName property.
Console.WriteLine("attribute.MachineName: {0}",
attribute.MachineName);
}
public void PathExample()
{
// Connect to a queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute attribute =
new MessageQueuePermissionAttribute(
System.Security.Permissions.SecurityAction.Assert);
// Set the attribute's Path property value, based on the queue's Path
// property value.
attribute.Path = queue.Path;
// Display the new value of the attribute's Path property.
Console.WriteLine("attribute.Path: {0}", attribute.Path);
}
public void PermissionAccessExample()
{
// Connect to a queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute attribute =
new MessageQueuePermissionAttribute(
System.Security.Permissions.SecurityAction.Assert);
// Set the attribute's PermissionAccess property value.
attribute.PermissionAccess = MessageQueuePermissionAccess.Receive;
// Display the new value of the attribute's PermissionAccess property.
Console.WriteLine("attribute.PermissionAccess: {0}",
attribute.PermissionAccess);
}
public void CreatePermissionExample()
{
// Connect to a queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleQueue");
// Create a new instance of MessageQueuePermissionAttribute.
MessageQueuePermissionAttribute attribute =
new MessageQueuePermissionAttribute(
System.Security.Permissions.SecurityAction.Assert);
// Set the attribute's Path property value, based on the queue's Path
// property value.
attribute.Path = queue.Path;
// Get an IPermission interface by calling the attribute's
// CreatePermission() method.
System.Security.IPermission permission = attribute.CreatePermission();
}
}
注解
有关使用特性的详细信息,请参阅 特性。
构造函数
MessageQueuePermissionAttribute(SecurityAction) |
初始化 MessageQueuePermissionAttribute 类的新实例。 |
属性
Action |
获取或设置安全性操作。 (继承自 SecurityAttribute) |
Category |
获取或设置队列类别。 |
Label |
获取或设置队列说明。 |
MachineName |
获取或设置“消息队列”队列所在的计算机的名称。 |
Path |
获取或设置队列的路径。 |
PermissionAccess |
获取或设置权限请求中使用的权限访问级别。 |
TypeId |
在派生类中实现时,获取此 Attribute 的唯一标识符。 (继承自 Attribute) |
Unrestricted |
获取或设置一个值,该值指示是否声明了对受该特性保护的资源有完全(无限制的)权限。 (继承自 SecurityAttribute) |
方法
CreatePermission() |
基于请求的访问级别、类别、标签、计算机名称和路径(它们是通过有关该特性上的 PermissionAccess、Category、Label、MachineName 和 Path 属性分别设置的)创建权限。 |
Equals(Object) |
返回一个值,该值指示此实例是否与指定的对象相等。 (继承自 Attribute) |
GetHashCode() |
返回此实例的哈希代码。 (继承自 Attribute) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
IsDefaultAttribute() |
在派生类中重写时,指示此实例的值是否是派生类的默认值。 (继承自 Attribute) |
Match(Object) |
当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。 (继承自 Attribute) |
MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
ToString() |
返回表示当前对象的字符串。 (继承自 Object) |
显式接口实现
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
将一组名称映射为对应的一组调度标识符。 (继承自 Attribute) |
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
检索对象的类型信息,然后可以使用该信息获取接口的类型信息。 (继承自 Attribute) |
_Attribute.GetTypeInfoCount(UInt32) |
检索对象提供的类型信息接口的数量(0 或 1)。 (继承自 Attribute) |
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供对某一对象公开的属性和方法的访问。 (继承自 Attribute) |