AspNetHostingPermission 类

定义

ASP.NET 寄宿的环境中的控件访问权限。Controls access permissions in ASP.NET hosted environments. 此类不能被继承。This class cannot be inherited.

public ref class AspNetHostingPermission sealed : System::Security::CodeAccessPermission, System::Security::Permissions::IUnrestrictedPermission
public sealed class AspNetHostingPermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
[System.Serializable]
public sealed class AspNetHostingPermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
type AspNetHostingPermission = class
    inherit CodeAccessPermission
    interface IUnrestrictedPermission
Public NotInheritable Class AspNetHostingPermission
Inherits CodeAccessPermission
Implements IUnrestrictedPermission
继承
AspNetHostingPermission
属性
实现

示例

下面的代码示例演示使用 AspNetHostingPermission 权限保护的类。The following code example shows a class protected using the AspNetHostingPermission permission. 若要创建类的实例,代码必须至少以 MinimalAspNetHostingPermission 权限 Level 运行。Code must be running with at least MinimalAspNetHostingPermission permission Level in order to create an instance of the class.

using System;
using System.Web;
using System.Security.Permissions;

[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Medium)]
public class CustomAspNetClass
{
}
Imports System.Web
Imports System.Security.Permissions

<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Medium)> _
Public Class CustomAspNetClass

End Class

注解

AspNetHostingPermission 类与代码访问安全性结合使用,以帮助保护 System.web 命名空间中的公共类型。The AspNetHostingPermission class is used in conjunction with code access security to help protect public types in the System.Web namespaces. 必须至少为代码分配 Minimal 信任级别才能访问受保护的 ASP.NET 类。Code must be assigned at least the Minimal trust level to access protected ASP.NET classes.

AspNetHostingPermission 类的 Level 属性通过在信任配置元素中配置适当的信任级别来设置。The AspNetHostingPermission class's Level property is set by configuring the appropriate trust level in the trust configuration element. 默认情况下,trust 配置元素的 level 特性设置为 FullBy default, the level attribute of the trust configuration element is set to Full. 也就是说,默认情况下,ASP.NET 应用程序在 Unrestricted 级别下运行。That is, by default, ASP.NET applications run under the Unrestricted level. 创建 ASP.NET 应用程序域时,ASP.NET 将读取为 trust 配置元素的 level 特性指定的值,使用指定的 Level 特性创建该 AspNetHostingPermission 类的实例,然后将该类添加到该应用程序域的权限集。When an ASP.NET application domain is created, ASP.NET reads the value specified for the level attribute of the trust configuration element, creates an instance of the AspNetHostingPermission class with the specified Level attribute, and then adds the class to the permission set for the application domain. 有关详细信息,请参阅ASP.NET 信任级别和策略文件For more information, see ASP.NET Trust Levels and Policy Files.

建议将 trust 配置元素的 level 属性设置为 "受信任的站点 High"。It is recommended that you set the level attribute of the trust configuration element to High for sites that are trusted. 对于不受信任的站点(如承载运行来自外部客户的代码的站点的 Web 服务器),建议将 trust 配置元素的 level 属性设置为 "Medium"。For sites that are not trusted, such as a Web server that hosts sites that run code from an external customer, it is recommended that you set the level attribute of the trust configuration element to Medium.

默认情况下为 .NET Framework (例如,LocalIntranet、Internet 等)定义的权限集不包括 AspNetHostingPermission 权限。The permission sets that are defined by default for the .NET Framework (for example, LocalIntranet, Internet, and so on) do not include the AspNetHostingPermission permission. 也就是说,默认情况下,AspNetHostingPermission 权限仅分配给在 Full 信任下运行的应用程序。That is, the AspNetHostingPermission permission is only assigned, by default, to applications that are running under Full trust.

构造函数

AspNetHostingPermission(AspNetHostingPermissionLevel)

使用指定的权限级别初始化 AspNetHostingPermission 类的新实例。Initializes a new instance of the AspNetHostingPermission class with the specified permission level.

AspNetHostingPermission(PermissionState)

使用指定的 PermissionState 枚举值初始化 AspNetHostingPermission 类的新实例。Initializes a new instance of the AspNetHostingPermission class with the specified PermissionState enumeration value.

属性

Level

获取或设置 ASP.NET 应用程序的当前宿主权限级别。Gets or sets the current hosting permission level for an ASP.NET application.

方法

Assert()

声明调用代码能够通过调用此方法的代码,访问受权限请求保护的资源,即使未对堆栈中处于较高位置的调用方授予访问该资源的权限。Declares that the calling code can access the resource protected by a permission demand through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource. 使用 Assert() 会引起安全问题。Using Assert() can create security issues.

(继承自 CodeAccessPermission)
Copy()

由派生类实现时,创建并返回当前权限对象的相同副本。When implemented by a derived class, creates and returns an identical copy of the current permission object.

Demand()

如果未对调用堆栈中处于较高位置的所有调用方授予当前实例所指定的权限,则在运行时强制 SecurityExceptionForces a SecurityException at run time if all callers higher in the call stack have not been granted the permission specified by the current instance.

(继承自 CodeAccessPermission)
Deny()

防止处于调用堆栈较高位置的调用函数使用可以调用此方法来访问当前实例指定资源的代码。Prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.

(继承自 CodeAccessPermission)
Equals(Object)

确定指定的 CodeAccessPermission 对象是否等于当前的 CodeAccessPermissionDetermines whether the specified CodeAccessPermission object is equal to the current CodeAccessPermission.

(继承自 CodeAccessPermission)
FromXml(SecurityElement)

从 XML 编码重新构造具有指定状态的权限对象。Reconstructs a permission object with a specified state from an XML encoding.

GetHashCode()

获取 CodeAccessPermission 对象的哈希代码,此代码适合在哈希算法和数据结构(例如哈希表)中使用。Gets a hash code for the CodeAccessPermission object that is suitable for use in hashing algorithms and data structures such as a hash table.

(继承自 CodeAccessPermission)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
Intersect(IPermission)

由派生类实现时,创建并返回属于当前权限和指定权限的交集的权限。When implemented by a derived class, creates and returns a permission that is the intersection of the current permission and the specified permission.

IsSubsetOf(IPermission)

返回一个值,该值指示当前权限是否为指定权限的一个子集。Returns a value indicating whether the current permission is a subset of the specified permission.

IsUnrestricted()

返回一个值,该值指示是否允许对受当前权限保护的资源进行不受限制地访问。Returns a value indicating whether unrestricted access to the resource that is protected by the current permission is allowed.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
PermitOnly()

防止处于调用堆栈较高位置的调用函数使用此代码,此代码将调用此方法来访问除当前实例指定的资源以外的所有资源。Prevents callers higher in the call stack from using the code that calls this method to access all resources except for the resource specified by the current instance.

(继承自 CodeAccessPermission)
ToString()

创建并返回当前权限对象的字符串表示形式。Creates and returns a string representation of the current permission object.

(继承自 CodeAccessPermission)
ToXml()

创建权限对象及其当前状态的 XML 编码。Creates an XML encoding of the permission object and its current state.

Union(IPermission)

创建一个权限,该权限是当前权限与指定权限的并集。Creates a permission that is the union of the current permission and the specified permission.

显式接口实现

IPermission.Demand() (继承自 CodeAccessPermission)
IStackWalk.Assert() (继承自 CodeAccessPermission)
IStackWalk.Demand() (继承自 CodeAccessPermission)
IStackWalk.Deny() (继承自 CodeAccessPermission)
IStackWalk.PermitOnly() (继承自 CodeAccessPermission)

适用于

另请参阅