Поделиться через


How to: Request Permission for a Named Permission Set 

Instead of requesting individual permissions (using RequestMinimum, RequestOptional, or RequestRefuse), you can request any of the following built-in permission sets: Nothing, Execution, FullTrust, Internet, LocalIntranet, and SkipVerification. You cannot request custom named permission sets or the Everything modifiable built-in permission set because the permissions they represent can vary. The following example shows the syntax to request permission for a named permission set. It attaches a PermissionSetAttribute with a Name value representing the name of the desired permission set.

Example

Imports System
Imports System.Runtime.InteropServices
Imports System.Security.Permissions
'The attribute is placed at the assembly level.
<assembly: PermissionSetAttribute(SecurityAction.RequestMinimum, Name := "FullTrust")>
Namespace MyNamespace
   Public Class [MyClass]
      Public Sub New()
      End Sub
      
      Public Sub MyMethod()
         'Perform operations that require permissions here.
      End Sub 
   End Class
End Namespace
//The attribute is placed at the assembly level.
using System.Security.Permissions;
[assembly:PermissionSetAttribute(SecurityAction.RequestMinimum, Name = "FullTrust")]
namespace MyNamespace
{
   using System;
   using System.Runtime.InteropServices;
   
   public class MyClass
   {
      public MyClass()
      {
      }
      public void MyMethod()
      {
      //Perform operations that require permissions here.
      }
   }
}

See Also

Concepts

Requesting Permissions

Other Resources

Extending Metadata Using Attributes
Code Access Security