System.Security.NamedPermissionSet Class

Assembly: Mscorlib.dll
Namespace: System.Security
Summary
Defines a permission set that has a name and description associated with it. This class cannot be inherited.
C# Syntax:
[Serializable]
public sealed class NamedPermissionSet : PermissionSet
Remarks
Named permission sets are used in security policy administration to specify the permissions to be granted to code that belongs to certain code groups. Names are strings of alphanumeric characters. Description strings can consist of any printable characters.
See also:
System.Security Namespace

System.Security.NamedPermissionSet Member List:

Public Constructors
ctor #1 Overloaded:
.ctor(NamedPermissionSet permSet)

Initializes a new instance of the NamedPermissionSet class from another named permission set.
ctor #2 Overloaded:
.ctor(string name)

Initializes a new, empty instance of the NamedPermissionSet class with the specified name.
ctor #3 Overloaded:
.ctor(string name, PermissionSet permSet)

Initializes a new instance of the NamedPermissionSet class with the specified name from a permission set.
ctor #4 Overloaded:
.ctor(string name, PermissionState state)

Initializes a new instance of the NamedPermissionSet class with the specified name in either an unrestricted or a fully restricted state.
Public Properties
Count
(inherited from System.Security.PermissionSet)
Read-only

See base class member description: System.Security.PermissionSet.Count


Gets the number of permission objects contained in the permission set.
Description Read-write

Gets or sets the text description of the current named permission set.
IsReadOnly
(inherited from System.Security.PermissionSet)
Read-only

See base class member description: System.Security.PermissionSet.IsReadOnly


Gets a value indicating whether the collection is read-only.
IsSynchronized
(inherited from System.Security.PermissionSet)
Read-only

See base class member description: System.Security.PermissionSet.IsSynchronized


Gets a value indicating whether the collection is guaranteed to be thread safe.
Name Read-write

Gets or sets the name of the current named permission set.
SyncRoot
(inherited from System.Security.PermissionSet)
Read-only

See base class member description: System.Security.PermissionSet.SyncRoot


Gets the root object of the current collection.
Public Methods
AddPermission
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.AddPermission


Adds a specified permission to the PermissionSet.
Assert
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.Assert


Asserts that the calling code can access the resource contained in the set through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource.
ContainsNonCodeAccessPermissions
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.ContainsNonCodeAccessPermissions


Gets a value indicating whether the PermissionSet contains permissions that are not derived from CodeAccessPermission.
Copy Overloaded:
Copy()

Overridden:
Creates a permission set copy from a named permission set.
Copy Overloaded:
Copy(string name)

Creates a copy of the named permission set with a different name but the same permissions.
CopyTo
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.CopyTo


Copies the permission objects of the set to the indicated location in an Array.
Demand
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.Demand


Forces a SecurityException at run time if all callers higher in the call stack have not been granted the permissions specified by the current instance.
Deny
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.Deny


Causes any PermissionSet.Demand that passes through the calling code for a permission that has an intersection with a permission of a type contained in the current PermissionSet to fail.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
FromXml Overridden:
Reconstructs a named permission set with a specified state from an XML encoding.
GetEnumerator
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.GetEnumerator


Returns an enumerator for the permissions of the set.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetPermission
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.GetPermission


Gets a permission object of the specified type, if it exists in the set.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
Intersect
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.Intersect


Creates and returns a permission that is the intersection of the current PermissionSet and the specified PermissionSet.
IsEmpty
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.IsEmpty


Gets a value indicating whether the PermissionSet is empty.
IsSubsetOf
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.IsSubsetOf


Determines whether the current PermissionSet is a subset of the specified PermissionSet.
IsUnrestricted
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.IsUnrestricted


Determines whether the PermissionSet is Unrestricted.
PermitOnly
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.PermitOnly


Causes any PermissionSet.Demand that passes through the calling code for any PermissionSet that is not a subset of the current PermissionSet to fail.
RemovePermission
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.RemovePermission


Removes a permission of a certain type from the set.
SetPermission
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.SetPermission


Sets a permission to the PermissionSet, replacing any existing permission of the same type.
ToString
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.ToString


Returns a string representation of the PermissionSet.
ToXml Overridden:
Creates an XML element description of the named permission set.
Union
(inherited from System.Security.PermissionSet)
See base class member description: System.Security.PermissionSet.Union


Creates a PermissionSet that is the union of the current PermissionSet and the specified PermissionSet.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Security.NamedPermissionSet Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the NamedPermissionSet class from another named permission set.
C# Syntax:
public NamedPermissionSet(NamedPermissionSet(
   NamedPermissionSet permSet
);
Parameters:

permSet

The named permission set from which to create the new instance.

Return to top


Overloaded ctor #2
Summary
Initializes a new, empty instance of the NamedPermissionSet class with the specified name.
C# Syntax:
public NamedPermissionSet(
   string name
);
Parameters:

name

The name for the new named permission set.

Exceptions
Exception Type Condition
ArgumentException The name parameter is not a valid name (such as null or empty string ("")).
Remarks
Use this method to create an empty named permission set, then extend it by adding permissions.

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the NamedPermissionSet class with the specified name from a permission set.
C# Syntax:
public NamedPermissionSet(
   string name,
   PermissionSet permSet
);
Parameters:

name

The name for the named permission set.

permSet

The permission set from which to take the value of the new named permission set.

Exceptions
Exception Type Condition
ArgumentException The name parameter is not a valid name (such as null or empty string ("")).

Return to top


Overloaded ctor #4
Summary
Initializes a new instance of the NamedPermissionSet class with the specified name in either an unrestricted or a fully restricted state.
C# Syntax:
public NamedPermissionSet(
   string name,
   PermissionState state
);
Parameters:

name

The name for the new named permission set.

state

One of the PermissionState values.

Exceptions
Exception Type Condition
ArgumentException The name parameter is not a valid name (such as null or empty string ("")).
Remarks
A named permission set in an unrestricted state effectively contains all permissions that implement the IUnrestrictedPermission interface. The named permission set will contain all built-in permissions as well as all custom user-defined permissions. All permissions will have the equivalent of an Unrestricted PermissionState. Permissions that do not implement IUnrestrictedPermission (such as identity permissions) will be empty instances.

Return to top


Property: Count (read-only)
Inherited
See base class member description: System.Security.PermissionSet.Count

Summary
Gets the number of permission objects contained in the permission set.
C# Syntax:
public virtual int Count {get;}
Implements:
ICollection.Count
Remarks
In the None or Unrestricted state this returns zero, because no actual permission object instances are used.

Return to top


Property: Description (read-write)
Summary
Gets or sets the text description of the current named permission set.
C# Syntax:
public string Description {get; set;}
Remarks
The description helps the administrator understand in words what permissions the set contains and its intended use.
Example
The following example creates a new NamedPermissionSet with the name "Empty" and the description "This permission set contains no permissions."
 NamedPermissionSet namedpset = new NamedPermissionSet ("Empty");
 namedpset.Description = "This permission set contains no permissions.";

    

Return to top


Property: IsReadOnly (read-only)
Inherited
See base class member description: System.Security.PermissionSet.IsReadOnly

Summary
Gets a value indicating whether the collection is read-only.
C# Syntax:
public virtual bool IsReadOnly {get;}
Remarks
A PermissionSet cannot be read-only, so this property is always false.

Return to top


Property: IsSynchronized (read-only)
Inherited
See base class member description: System.Security.PermissionSet.IsSynchronized

Summary
Gets a value indicating whether the collection is guaranteed to be thread safe.
C# Syntax:
public virtual bool IsSynchronized {get;}
Implements:
ICollection.IsSynchronized
Remarks
PermissionSet does not automatically handle thread safety, so this property is always false.

This method is required to support ICollection.

Return to top


Property: Name (read-write)
Summary
Gets or sets the name of the current named permission set.
C# Syntax:
public string Name {get; set;}
Exceptions
Exception Type Condition
ArgumentException The name is not a valid name (such as null or empty string ("")).
Remarks
Code groups refer to permission sets by name.
Example
The following example creates a new NamedPermissionSet with the name "none" and then renames it to "Empty."
 NamedPermissionSet namedpset = new NamedPermissionSet ("none");
 namedpset.Name = "Empty";    // change name of permission set to "Empty"

    

Return to top


Property: SyncRoot (read-only)
Inherited
See base class member description: System.Security.PermissionSet.SyncRoot

Summary
Gets the root object of the current collection.
C# Syntax:
public virtual object SyncRoot {get;}
Implements:
ICollection.SyncRoot
Remarks
This method is required to support ICollection.

Return to top


Method: AddPermission(
   IPermission perm
)
Inherited
See base class member description: System.Security.PermissionSet.AddPermission

Summary
Adds a specified permission to the PermissionSet.
C# Syntax:
public virtual IPermission AddPermission(
   IPermission perm
);
Parameters:

perm

The permission to add.

Return Value:
The union of the permission added and any permission of the same type that already exists in the PermissionSet.
Exceptions
Exception Type Condition
ArgumentException The perm parameter is not a permission object.
Remarks
If a permission of the same type as the added permission already exists in the PermissionSet, the new permission is the union of the existing permission object and the specified permission object. For example, if a permission that implements IUnrestrictedPermission is added to an PermissionState.Unrestricted PermissionSet, the resulting union is the original Unrestricted PermissionSet.

Return to top


Method: Assert()
Inherited
See base class member description: System.Security.PermissionSet.Assert

Summary
Asserts that the calling code can access the resource contained in the set through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource.
C# Syntax:
public virtual void Assert();
Exceptions
Exception Type Condition
SecurityException The PermissionSet instance asserted has not been granted to the asserting code.
Implements:
IStackWalk.Assert
Remarks
This is the only way to assert multiple permissions at the same time within a frame because only one PermissionSet.Assert can be active on a frame. PermissionSet.Assert is only effective for granted permissions.
See also:
MSDN: assert

Return to top


Method: ContainsNonCodeAccessPermissions()
Inherited
See base class member description: System.Security.PermissionSet.ContainsNonCodeAccessPermissions

Summary
Gets a value indicating whether the PermissionSet contains permissions that are not derived from CodeAccessPermission.
C# Syntax:
public bool ContainsNonCodeAccessPermissions();
Return Value:
true if the PermissionSet contains permissions that are not derived from CodeAccessPermission; otherwise, false.

Return to top


Overloaded Method: Copy()
Summary
Creates a permission set copy from a named permission set.
C# Syntax:
public override PermissionSet Copy();
Return Value:
A permission set that is a copy of the permissions in the named permission set.

Return to top


Overloaded Method: Copy(
   string name
)
Summary
Creates a copy of the named permission set with a different name but the same permissions.
C# Syntax:
public NamedPermissionSet Copy(
   string name
);
Parameters:

name

The name for the new named permission set.

Return Value:
A copy of the named permission set with the new name.
Exceptions
Exception Type Condition
ArgumentException The name parameter is not a valid name (such as null or empty string ("")).

Return to top


Method: CopyTo(
   Array array,
   int index
)
Inherited
See base class member description: System.Security.PermissionSet.CopyTo

Summary
Copies the permission objects of the set to the indicated location in an Array.
C# Syntax:
public virtual void CopyTo(
   Array array,
   int index
);
Parameters:

array

The target array to which to copy.

index

The starting position in the array to begin copying (zero based).

Exceptions
Exception Type Condition
ArgumentException The index parameter is out of the range of the array parameter.
ArgumentNullException The array parameter is null.
Implements:
ICollection.CopyTo

Return to top


Method: Demand()
Inherited
See base class member description: System.Security.PermissionSet.Demand

Summary
Forces a SecurityException at run time if all callers higher in the call stack have not been granted the permissions specified by the current instance.
C# Syntax:
public virtual void Demand();
Exceptions
Exception Type Condition
SecurityException A caller in the call chain does not have the permission demanded.
Implements:
IStackWalk.Demand
Remarks
Use PermissionSet.Demand on a PermissionSet to ensure that all callers have all permissions in the set with one operation.

The permissions of the code that calls this method are not examined; the check begins from the immediate caller of that code and proceeds up the stack. The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack. PermissionSet.Demand succeeds only if no SecurityException is thrown.

If the PermissionSet contains permissions that do not inherit from CodeAccessPermission, the Demand methods of those permissions are called as well.

See also:
MSDN: makingsecuritydemands

Return to top


Method: Deny()
Inherited
See base class member description: System.Security.PermissionSet.Deny

Summary
Causes any PermissionSet.Demand that passes through the calling code for a permission that has an intersection with a permission of a type contained in the current PermissionSet to fail.
C# Syntax:
public virtual void Deny();
Implements:
IStackWalk.Deny
Remarks
This method prevents callers higher in the call stack from accessing the protected resource through the code that calls this method, even if those callers have been granted permission to access it. The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack.

PermissionSet.Deny can limit the liability of the programmer or prevent accidental security vulnerabilities because it prevents the method that calls PermissionSet.Deny from being used to access the resource protected by the denied permission. If a method calls PermissionSet.Deny on a permission, and if a PermissionSet.Demand for that permission is invoked by a caller lower in the call stack, that security check fails when it reaches the PermissionSet.Deny.

PermissionSet.Deny is ignored for a permission that is not granted because a demand for that permission cannot succeed.

See also:
MSDN: deny | MSDN: overridingsecuritychecks

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~NamedPermissionSet();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: FromXml(
   SecurityElement et
)
Summary
Reconstructs a named permission set with a specified state from an XML encoding.
C# Syntax:
public override void FromXml(
   SecurityElement et
);
Parameters:

et

A security element containing the XML representation of the named permission set.

Exceptions
Exception Type Condition
ArgumentException The et parameter is not a valid representation of a named permission set.
ArgumentNullException The et parameter is null.
Implements:
ISecurityEncodable.FromXml
Remarks
This method recreates the state of a named permission set from an XML element previously created by NamedPermissionSet.ToXml.

Return to top


Method: GetEnumerator()
Inherited
See base class member description: System.Security.PermissionSet.GetEnumerator

Summary
Returns an enumerator for the permissions of the set.
C# Syntax:
public virtual IEnumerator GetEnumerator();
Return Value:
An enumerator object for the permissions of the set.
Implements:
IEnumerable.GetEnumerator
Remarks
Use the enumerator as an index to access individual permission objects in the set.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetPermission(
   Type permClass
)
Inherited
See base class member description: System.Security.PermissionSet.GetPermission

Summary
Gets a permission object of the specified type, if it exists in the set.
C# Syntax:
public virtual IPermission GetPermission(
   Type permClass
);
Parameters:

permClass

The Type of the desired permission object.

Return Value:
A copy of the permission object of the type specified by the permClass parameter contained in the PermissionSet, or null if none exists.
Remarks
The method returns null for an Unrestricted PermissionSet. Although an Unrestricted PermissionSet effectively contains all permissions, it does not have any actual instances to return.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Intersect(
   PermissionSet other
)
Inherited
See base class member description: System.Security.PermissionSet.Intersect

Summary
Creates and returns a permission that is the intersection of the current PermissionSet and the specified PermissionSet.
C# Syntax:
public virtual PermissionSet Intersect(
   PermissionSet other
);
Parameters:

other

A PermissionSet to intersect with the current PermissionSet.

Return Value:
A new PermissionSet that represents the intersection of the current PermissionSet and the specified target. This object is null if the intersection is empty.
Remarks
The intersection of two permission sets is a permission set that describes the set of operations they both describe in common. Specifically, it represents the minimum permissions such that any demand that passes both permission sets also passes their intersection.

For each type of permission that is present in both sets, the two instances of those permissions are intersected using the permission's Intersect method; the resulting permission is included in the resulting PermissionSet. Permission types that exist in only one of the two sets are excluded from the resulting set.

Return to top


Method: IsEmpty()
Inherited
See base class member description: System.Security.PermissionSet.IsEmpty

Summary
Gets a value indicating whether the PermissionSet is empty.
C# Syntax:
public virtual bool IsEmpty();
Return Value:
true if the PermissionSet is empty; otherwise, false.
Remarks
A PermissionSet can be empty and yet contain instances of permissions if those permissions are in the fully-restricted state. Permissions are in a fully restricted state if their IsSubsetOf methods return true when null is passed as a parameter.

Return to top


Method: IsSubsetOf(
   PermissionSet target
)
Inherited
See base class member description: System.Security.PermissionSet.IsSubsetOf

Summary
Determines whether the current PermissionSet is a subset of the specified PermissionSet.
C# Syntax:
public virtual bool IsSubsetOf(
   PermissionSet target
);
Parameters:

target

A PermissionSet to test for the subset relationship. This must be either a PermissionSet or a NamedPermissionSet.

Return Value:
true if the current PermissionSet is a subset of the target parameter; otherwise, false.
Remarks
A PermissionSet is a subset of the target PermissionSet if all demands that succeed for the PermissionSet also succeed for the target. That is, the target contains at least the permissions contained in the subset.

Return to top


Method: IsUnrestricted()
Inherited
See base class member description: System.Security.PermissionSet.IsUnrestricted

Summary
Determines whether the PermissionSet is Unrestricted.
C# Syntax:
public virtual bool IsUnrestricted();
Return Value:
true if the PermissionSet is Unrestricted; otherwise, false.
Remarks
An Unrestricted PermissionSet effectively contains all permissions that implement the IUnrestrictedPermission interface.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: PermitOnly()
Inherited
See base class member description: System.Security.PermissionSet.PermitOnly

Summary
Causes any PermissionSet.Demand that passes through the calling code for any PermissionSet that is not a subset of the current PermissionSet to fail.
C# Syntax:
public virtual void PermitOnly();
Implements:
IStackWalk.PermitOnly
Remarks
PermissionSet.PermitOnly is similar to PermissionSet.Deny, in that both cause stack walks to fail when they would otherwise succeed. The difference is that PermissionSet.Deny specifies permissions that will cause the stack walk to fail, but PermissionSet.PermitOnly specifies the only permissions that do not cause the stack walk to fail. Call this method to ensure that your code can be used to access only the specified resources.

PermissionSet.PermitOnly is ignored for a permission not granted because a demand for that permission cannot succeed. However, if code lower on the call stack later calls PermissionSet.Demand for that permission, a SecurityException is thrown when the stack walk reaches the code that tried to call PermissionSet.PermitOnly. This is because the code that called PermissionSet.PermitOnly has not been granted the permission, even though it called PermissionSet.PermitOnly for that permission. The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack.

See also:
MSDN: permitonly | MSDN: overridingsecuritychecks

Return to top


Method: RemovePermission(
   Type permClass
)
Inherited
See base class member description: System.Security.PermissionSet.RemovePermission

Summary
Removes a permission of a certain type from the set.
C# Syntax:
public virtual IPermission RemovePermission(
   Type permClass
);
Parameters:

permClass

The Type of permission to delete.

Return Value:
The permission removed from the set.

Return to top


Method: SetPermission(
   IPermission perm
)
Inherited
See base class member description: System.Security.PermissionSet.SetPermission

Summary
Sets a permission to the PermissionSet, replacing any existing permission of the same type.
C# Syntax:
public virtual IPermission SetPermission(
   IPermission perm
);
Parameters:

perm

The permission to set.

Return Value:
The set permission.
Remarks
This method removes any existing permission object of the same type from the PermissionSet and replaces it with the perm parameter. If a permission that implements IUnrestrictedPermission is set on a PermissionSet that is PermissionState.Unrestricted, the resulting PermissionSet is no longer Unrestricted.

Return to top


Method: ToString()
Inherited
See base class member description: System.Security.PermissionSet.ToString

Summary
Returns a string representation of the PermissionSet.
C# Syntax:
public override string ToString();
Return Value:
A representation of the PermissionSet.
Remarks
The string representation is useful in debugging to see the state of a PermissionSet.

Return to top


Overridden Method: ToXml()
Summary
Creates an XML element description of the named permission set.
C# Syntax:
public override SecurityElement ToXml();
Return Value:
The XML representation of the named permission set.
Implements:
ISecurityEncodable.ToXml
Remarks
Use NamedPermissionSet.FromXml to recreate the state represented by the returned element.

Return to top


Method: Union(
   PermissionSet other
)
Inherited
See base class member description: System.Security.PermissionSet.Union

Summary
Creates a PermissionSet that is the union of the current PermissionSet and the specified PermissionSet.
C# Syntax:
public virtual PermissionSet Union(
   PermissionSet other
);
Parameters:

other

A PermissionSet to form the union with the current PermissionSet.

Return Value:
A new PermissionSet that represents the union of the current PermissionSet and the specified PermissionSet.
Remarks
The result of a call to PermissionSet.Union is a PermissionSet that represents all the operations represented by the current PermissionSet as well as all the operations represented by the specified PermissionSet. If either set is Unrestricted, the union is Unrestricted as well.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.