PermissionSet.SetPermission Method (IPermission)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Sets a permission to the PermissionSet, replacing any existing permission of the same type.

Namespace:   System.Security
Assembly:  mscorlib (in mscorlib.dll)

Public Function SetPermission (
	perm As IPermission
) As IPermission


Type: System.Security.IPermission

The permission to set.

Return Value

Type: System.Security.IPermission

The set permission.

Exception Condition

The method is called from a ReadOnlyPermissionSet.

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 Unrestricted, the resulting PermissionSet is no longer Unrestricted.

Notes to Inheritors:

When you inherit from PermissionSet, you can change the behavior of the SetPermission method by overriding the SetPermissionImpl method.

The following code example shows the use of the SetPermission method. This code example is part of a larger example provided for the PermissionSet class.

' Change the permission set using SetPermission.
ps5.SetPermission(New EnvironmentPermission(EnvironmentPermissionAccess.AllAccess, "USERNAME"))
Console.WriteLine("Permission set after SetPermission = " & ps5.ToString())

.NET Framework
Available since 1.1
Return to top