IdentityPermissionSet Class
System.Net.Security
Introduction
The IdentityPermissionSet class represents a set of identity permissions. Identity permissions are used to control access to resources based on the identity of the code or user requesting access. This class provides methods for managing and comparing sets of identity permissions.
Syntax
public sealed class IdentityPermissionSet : PermissionSet, System.Collections.ICollection, System.Collections.IEnumerable
Members
Constructors
IdentityPermissionSet()
Initializes a new instance of the IdentityPermissionSet class with default settings.
public IdentityPermissionSet();
IdentityPermissionSet(PermissionSet value)
Initializes a new instance of the IdentityPermissionSet class based on an existing PermissionSet.
public IdentityPermissionSet(PermissionSet value);
Parameters
| Name | Type | Description |
|---|---|---|
value |
PermissionSet |
The PermissionSet to copy from. |
Methods
AddPermission
Adds a permission to the current permission set.
public void AddPermission(IPermission perm);
Parameters
| Name | Type | Description |
|---|---|---|
perm |
IPermission |
The IPermission to add. |
Copy
Creates and returns an identical copy of the current permission set.
public override IPermission Copy();
Equals
Determines whether the specified object is equal to the current permission set.
public override bool Equals(object obj);
Parameters
| Name | Type | Description |
|---|---|---|
obj |
object |
The object to compare with the current permission set. |
Returns
true if the specified object is equal to the current permission set; otherwise, false.
GetHashCode
Returns the hash code for the current permission set.
public override int GetHashCode();
Includes
Determines whether the current permission set includes all permissions in the specified permission set.
public override bool Includes(PermissionSet permSet);
Parameters
| Name | Type | Description |
|---|---|---|
permSet |
PermissionSet |
The PermissionSet to compare with the current permission set. |
Returns
true if the current permission set includes all permissions in the specified permission set; otherwise, false.
IsSubsetOf
Determines whether the current permission set is a subset of the specified permission set.
public override bool IsSubsetOf(PermissionSet permSet);
Parameters
| Name | Type | Description |
|---|---|---|
permSet |
PermissionSet |
The PermissionSet to compare with the current permission set. |
Returns
true if the current permission set is a subset of the specified permission set; otherwise, false.
Remarks
The IdentityPermissionSet class is used in conjunction with the Code Access Security (CAS) model in .NET Framework. It allows you to define and manage permissions related to the identity of code or users, which is crucial for enforcing security policies.
Example
Creating and using an IdentityPermissionSet
using System;
using System.Net.Security;
using System.Security.Permissions;
public class Example
{
public static void Main(string[] args)
{
// Create an IdentityPermissionSet
IdentityPermissionSet idPermissionSet = new IdentityPermissionSet();
// Create an identity permission (e.g., for a specific URL)
// Note: IdentityPermission is abstract, use a concrete derived class if available or a general IdentityPermission
// For demonstration, we'll use a hypothetical specific permission.
// In a real scenario, you might use UrlIdentityPermission or Zone IdentityPermission if available.
// Let's assume a hypothetical constructor for demonstration
// In reality, you might need to deserialize or construct specific types.
// For simplicity, we'll conceptualize adding a permission that grants access to "example.com"
// Placeholder for a specific Identity Permission (e.g., UrlIdentityPermission)
// The actual creation might involve deserialization or specific constructors.
// IPermission specificPermission = new UrlIdentityPermission("http://www.example.com");
// As a fallback for demonstration, let's simulate adding a conceptual permission.
// This part is illustrative and might not compile directly without concrete IdentityPermission types.
// Example of how you would typically add a permission if you had one:
// idPermissionSet.AddPermission(specificPermission);
Console.WriteLine("IdentityPermissionSet created.");
// In a real scenario, you would check if permissions are granted based on this set.
}
}
Requirements
| .NET Framework | .NET Standard | .NET Core |
|---|---|---|
| Supported in: 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.6, 4.7, 4.8 | Not directly applicable (CAS model is primarily .NET Framework) | Not directly applicable (CAS model is primarily .NET Framework) |