PageParserFilter Class


为 ASP.NET 分析器所使用的页分析器筛选器提供一个抽象基类,以确定分析时是否允许在页中包含某项。Provides an abstract base class for a page parser filter that is used by the ASP.NET parser to determine whether an item is allowed in the page at parse time.

public ref class PageParserFilter abstract
public abstract class PageParserFilter
type PageParserFilter = class
Public MustInherit Class PageParserFilter


下面的示例演示如何创建派生自 PageParserFilter 类的类,以控制 ASP.NET 页分析器的行为。The following example demonstrates how you can create a class that derives from the PageParserFilter class to govern the behavior of the ASP.NET page parser. CustomPageParserFilter 是在页面中显式拒绝代码的分析器筛选器。The CustomPageParserFilter is a parser filter that explicitly rejects code in the page. 它通过重写 AllowCode 属性来实现此功能。It does this by overriding the AllowCode property.

namespace Samples.AspNet.CS
    [PermissionSet(SecurityAction.Demand, Unrestricted = true)]
    public class CustomPageParserFilter : PageParserFilter
        public override bool AllowCode
                return false;
Namespace Samples.AspNet.VB
    <PermissionSet(SecurityAction.Demand, Unrestricted := true)> _
    Public Class CustomPageParserFilter
        Inherits PageParserFilter

        Public Overrides ReadOnly Property AllowCode() As Boolean
                Return False
            End Get
        End Property

    End Class
End Namespace

若要使用 CustomPageParserFilter 示例,请将类放置在 App_Code 目录中。To use the CustomPageParserFilter sample, place the class in your App_Code directory. 必须配置 ASP.NET 分析程序,才能使用站点的 web.config 配置文件的 pages 部分中的筛选器。You must configure the ASP.NET parsers to use the filter in the pages section of your site's Web.config configuration file. 下面的示例配置文件显示了 CustomPageParserFilter的配置。The following example configuration file shows the configuration for CustomPageParserFilter. 当配置为使用分析器筛选器时,如果在页面中遇到代码,则 ASP.NET 分析器会在生成过程中引发异常。When configured to use a parser filter, the ASP.NET parser throws an exception during the build if it encounters code in a page.

<?xml version="1.0" ?>

<configuration xmlns="">









初始化 PageParserFilter 类的新实例。Initializes a new instance of the PageParserFilter class.



获取一个值,该值指示 ASP.NET 分析器筛选器是否允许页上包含代码。Gets a value indicating whether an ASP.NET parser filter permits code on the page.


获取一个值,该值指示是否从页中调用了分析器筛选器。Gets a value that indicates whether the parser filter was called from the page.


获取文件中当前正在对其进行分析的行号。Gets the line number that is currently being parsed in the file.


获取分析器筛选器可为单个页分析的最大控件数。Gets the maximum number of controls that a parser filter can parse for a single page.


获取页分析器允许单个页包含的直接文件依赖项的最大数目。Gets the maximum number of direct file dependencies that the page parser permits for a single page.


获取页分析器允许单个页包含的直接和间接文件依赖项的最大数目。Gets the maximum number of direct and indirect file dependencies that the page parser permits for a single page.


获取指向当前分析的页的虚拟路径。Gets the virtual path to the page currently being parsed.


AddControl(Type, IDictionary)

在页控件树的当前页分析器位置中添加 ControlBuilder 对象。Adds a ControlBuilder object in the page control tree at the current page parser position.


确定页是否可以从指定的 Type 派生。Determines whether the page can be derived from the specified Type.

AllowControl(Type, ControlBuilder)

获取一个值,该值指示此页是否允许包含指定的控件类型。Gets a value indicating whether the specified control type is allowed for this page.


确定分析器是否允许在页上包含特定服务器端 include 语法。Determines whether a parser permits a specific server-side include on a page.

AllowVirtualReference(String, VirtualReferenceType)

确定分析器是否允许在页上包含对特定资源类型的虚引用。Determines whether a parser permits a virtual reference to a specific type of resource on a page.


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

(Inherited from Object)

检索页的当前编译模式。Retrieves the current compilation mode for the page.


作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)

返回应该用于未动态编译的页或控件的 TypeReturns a Type that should be used for pages or controls that are not dynamically compiled.


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

(Inherited from Object)

初始化用于页的筛选器。Initializes a filter used for a page.


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

(Inherited from Object)

由 ASP.NET 页分析器调用,以在完成对页的分析时通知筛选器。Called by an ASP.NET page parser to notify a filter when the parsing of a page is complete.

PreprocessDirective(String, IDictionary)

允许页分析器筛选器对页指令进行预处理。Allows the page parser filter to preprocess page directives.

ProcessCodeConstruct(CodeConstructType, String)

返回一个值,该值指示后续分析器筛选器是否应处理代码块。Returns a value that indicates whether a code block should be processed by subsequent parser filters.

ProcessDataBindingAttribute(String, String, String)

返回一个值,该值指示分析器筛选器是否处理特性中的数据绑定表达式。Returns a value that indicates whether the parser filter processes a data binding expression in an attribute.

ProcessEventHookup(String, String, String)

返回一个值,该值指示分析器筛选器是否应该进一步处理事件处理程序。Returns a value that indicates whether event handlers should be processed further by the parser filter.

SetPageProperty(String, String, String)

在从 TemplateControl 类派生的控件(包括 PageUserControlMasterPage 控件)上设置属性。Sets a property on a control derived from the TemplateControl class, which includes the Page, UserControl, and MasterPage controls.


返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also