PageParserFilter 類別


提供頁面剖析器篩選條件的抽象基底類別,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.


判斷頁面是否可以衍生自指定的 TypeDetermines 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.


判斷剖析器是否允許頁面上的特定伺服器端包含。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.

(繼承來源 Object)

擷取頁面目前的編譯模式。Retrieves the current compilation mode for the page.


做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)

傳回非動態編譯之頁面或控制項所應使用的 TypeReturns a Type that should be used for pages or controls that are not dynamically compiled.


取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)

初始化頁面使用的篩選條件。Initializes a filter used for a page.


建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 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.

(繼承來源 Object)