MessageQueuePermissionAttribute Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Tillåter deklarativa MessageQueue behörighetskontroller.
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
- Arv
- Attribut
Exempel
I följande kodexempel visas användningen av 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();
}
}
Kommentarer
Mer information om hur du använder attribut finns i Attribut.
Konstruktorer
| Name | Description |
|---|---|
| MessageQueuePermissionAttribute(SecurityAction) |
Initierar en ny instans av MessageQueuePermissionAttribute klassen. |
Egenskaper
| Name | Description |
|---|---|
| Action |
Hämtar eller anger en säkerhetsåtgärd. (Ärvd från SecurityAttribute) |
| Category |
Hämtar eller anger kökategorin. |
| Label |
Hämtar eller anger köbeskrivningen. |
| MachineName |
Hämtar eller anger namnet på datorn där Message Queuing-kön finns. |
| Path |
Hämtar eller anger köns sökväg. |
| PermissionAccess |
Hämtar eller anger behörighetsåtkomstnivåerna som används i behörighetsbegäran. |
| TypeId |
När den implementeras i en härledd klass hämtar du en unik identifierare för den här Attribute. (Ärvd från Attribute) |
| Unrestricted |
Hämtar eller anger ett värde som anger om fullständig (obegränsad) behörighet till resursen som skyddas av attributet deklareras. (Ärvd från SecurityAttribute) |
Metoder
| Name | Description |
|---|---|
| CreatePermission() |
Skapar behörigheten baserat på de begärda åtkomstnivåerna, kategorin, etiketten, datornamnet och sökvägen som anges via PermissionAccessegenskaperna , Category, Label, MachineNameoch Path för attributet. |
| Equals(Object) |
Returnerar ett värde som anger om den här instansen är lika med ett angivet objekt. (Ärvd från Attribute) |
| GetHashCode() |
Returnerar hash-koden för den här instansen. (Ärvd från Attribute) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| IsDefaultAttribute() |
När den åsidosättas i en härledd klass anger du om värdet för den här instansen är standardvärdet för den härledda klassen. (Ärvd från Attribute) |
| Match(Object) |
När den åsidosätts i en härledd klass returneras ett värde som anger om den här instansen är lika med ett angivet objekt. (Ärvd från Attribute) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
Explicita gränssnittsimplementeringar
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mappar en uppsättning namn till en motsvarande uppsättning av sändningsidentifierare. (Ärvd från Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Hämtar typinformationen för ett objekt, som kan användas för att hämta typinformationen för ett gränssnitt. (Ärvd från Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Hämtar antalet typinformationsgränssnitt som ett objekt tillhandahåller (antingen 0 eller 1). (Ärvd från Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Ger åtkomst till egenskaper och metoder som exponeras av ett objekt. (Ärvd från Attribute) |