如何:请求命名权限集的权限

更新:2007 年 11 月

您可以不请求单个权限(使用 RequestMinimumRequestOptionalRequestRefuse),而请求下面的任何内置权限集:NothingExecutionFullTrustInternetLocalIntranetSkipVerification。您不能请求自定义的命名权限集或 Everything 可修改的内置权限集,因为它们表示的权限可能会变化。下面的示例说明请求命名权限集的权限的语法。它将一个 PermissionSetAttribute 与表示所需权限集的名称的 Name 值连接起来。

示例

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.
      }
   }
}

请参见

概念

请求权限

其他资源

利用属性扩展元数据

代码访问安全性