Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
PagesSection Class
Collapse the table of content
Expand the table of content

PagesSection Class

Provides programmatic access to the pages section of the configuration file. This class cannot be inherited.

Namespace:  System.Web.Configuration
Assembly:  System.Web (in System.Web.dll)

public sealed class PagesSection : ConfigurationSection

The PagesSection type exposes the following members.

Public methodPagesSectionInfrastructure. Initializes a new instance of the PagesSection class using default settings.

Public propertyAsyncTimeoutGets or sets a value indicating the number of seconds to wait for an asynchronous handler to complete during asynchronous page processing.
Public propertyAutoEventWireupGets or sets a value indicating whether events for ASP.NET pages are automatically connected to event-handling functions.
Public propertyBufferGets or sets a value that specifies whether .aspx pages and .ascx controls use response buffering.
Public propertyClientIDModeGets or sets the default algorithm that is used to generate a control's identifier.
Public propertyCompilationModeGets or sets a value that determines how .aspx pages and .ascx controls are compiled.
Public propertyControlRenderingCompatibilityVersionGets or sets a value that specifies the ASP.NET version that any rendered HTML will be compatible with.
Public propertyControlsGets a collection of TagPrefixInfo objects.
Public propertyCurrentConfigurationGets a reference to the top-level Configuration instance that represents the configuration hierarchy that the current ConfigurationElement instance belongs to. (Inherited from ConfigurationElement.)
Public propertyElementInformationGets an ElementInformation object that contains the non-customizable information and functionality of the ConfigurationElement object. (Inherited from ConfigurationElement.)
Protected propertyElementPropertyGets the ConfigurationElementProperty object that represents the ConfigurationElement object itself. (Inherited from ConfigurationElement.)
Public propertyEnableEventValidationGets or sets a value that specifies whether event validation is enabled.
Public propertyEnableSessionStateGets or sets a value that specifies whether the session state is enabled, disabled, or read-only.
Public propertyEnableViewStateGets or sets a value indicating whether view state is enabled or disabled.
Public propertyEnableViewStateMacGets or sets a value that specifies whether ASP.NET should run a message authentication code (MAC) on the page's view state when the page is posted back from the client.
Public propertyIgnoreDeviceFiltersGets the collection of device tags that ASP.NET should ignore when it renders a page.
Protected propertyItem[ConfigurationProperty]Gets or sets a property or attribute of this configuration element. (Inherited from ConfigurationElement.)
Protected propertyItem[String]Gets or sets a property, attribute, or child element of this configuration element. (Inherited from ConfigurationElement.)
Public propertyLockAllAttributesExceptGets the collection of locked attributes. (Inherited from ConfigurationElement.)
Public propertyLockAllElementsExceptGets the collection of locked elements. (Inherited from ConfigurationElement.)
Public propertyLockAttributesGets the collection of locked attributes (Inherited from ConfigurationElement.)
Public propertyLockElementsGets the collection of locked elements. (Inherited from ConfigurationElement.)
Public propertyLockItemGets or sets a value indicating whether the element is locked. (Inherited from ConfigurationElement.)
Public propertyMaintainScrollPositionOnPostBackGets or sets a value indicating whether the page scroll position should be maintained upon returning from a postback from the server.
Public propertyMasterPageFileGets or sets a reference to the master page for the application.
Public propertyMaxPageStateFieldLengthGets or sets the maximum number of characters that a single view-state field can contain.
Public propertyNamespacesGets a collection of NamespaceInfo objects.
Public propertyPageBaseTypeGets or sets a value that specifies a code-behind class that .aspx pages inherit by default.
Public propertyPageParserFilterTypeGets or sets a value that specifies the parser filter type.
Protected propertyPropertiesGets the collection of properties. (Inherited from ConfigurationElement.)
Public propertyRenderAllHiddenFieldsAtTopOfFormGets or sets a value that indicates whether all system-generated hidden fields are rendered at the top of the form.
Public propertySectionInformationGets a SectionInformation object that contains the non-customizable information and functionality of the ConfigurationSection object. (Inherited from ConfigurationSection.)
Public propertySmartNavigationGets or sets a value that indicates whether smart navigation is enabled.
Public propertyStyleSheetThemeGets or sets the name of an ASP.NET style sheet theme.
Public propertyTagMappingGets a collection of TagMapInfo objects.
Public propertyThemeGets or sets the name of an ASP.NET page theme.
Public propertyUserControlBaseTypeGets or sets a value that specifies a code-behind class that user controls inherit by default.
Public propertyValidateRequestGets or sets a value that determines whether ASP.NET examines input from the browser for dangerous values. For more information, see Script Exploits Overview.
Public propertyViewStateEncryptionModeGets or sets the encryption mode that ASP.NET uses when maintaining ViewState values.

Protected methodDeserializeElementReads XML from the configuration file. (Inherited from ConfigurationElement.)
Protected methodDeserializeSectionInfrastructure. Reads XML from the configuration file. (Inherited from ConfigurationSection.)
Public methodEqualsCompares the current ConfigurationElement instance to the specified object. (Inherited from ConfigurationElement.)
Public methodGetHashCodeGets a unique value representing the current ConfigurationElement instance. (Inherited from ConfigurationElement.)
Protected methodGetRuntimeObjectReturns a custom object when overridden in a derived class. (Inherited from ConfigurationSection.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodInitSets the ConfigurationElement object to its initial state. (Inherited from ConfigurationElement.)
Protected methodInitializeDefaultUsed to initialize a default set of values for the ConfigurationElement object. (Inherited from ConfigurationElement.)
Protected methodIsModifiedIndicates whether this configuration element has been modified since it was last saved or loaded when implemented in a derived class. (Inherited from ConfigurationSection.)
Public methodIsReadOnlyGets a value indicating whether the ConfigurationElement object is read-only. (Inherited from ConfigurationElement.)
Protected methodResetResets the internal state of the ConfigurationElement object, including the locks and the properties collections. (Inherited from ConfigurationElement.)
Protected methodResetModifiedResets the value of the IsModified method to false when implemented in a derived class. (Inherited from ConfigurationSection.)
Protected methodSerializeElementWrites the contents of this configuration element to the configuration file when implemented in a derived class. (Inherited from ConfigurationElement.)
Protected methodSerializeSectionInfrastructure. Creates an XML string containing an unmerged view of the ConfigurationSection object as a single section to write to a file. (Inherited from ConfigurationSection.)
Protected methodSerializeToXmlElementWrites the outer tags of this configuration element to the configuration file when implemented in a derived class. (Inherited from ConfigurationElement.)
Protected methodSetReadOnlySets the IsReadOnly property for the ConfigurationElement object and all subelements. (Inherited from ConfigurationElement.)
Protected methodShouldSerializeElementInTargetVersionIndicates whether the specified element should be serialized when the configuration object hierarchy is serialized for the specified target version of the .NET Framework. (Inherited from ConfigurationSection.)
Protected methodShouldSerializePropertyInTargetVersionIndicates whether the specified property should be serialized when the configuration object hierarchy is serialized for the specified target version of the .NET Framework. (Inherited from ConfigurationSection.)
Protected methodShouldSerializeSectionInTargetVersionIndicates whether the current ConfigurationSection instance should be serialized when the configuration object hierarchy is serialized for the specified target version of the .NET Framework. (Inherited from ConfigurationSection.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Protected methodUnmergeModifies the ConfigurationElement object to remove all values that should not be saved. (Inherited from ConfigurationElement.)

The PagesSection class provides a way to programmatically access and modify the content of the configuration file pages section. This configuration section supports setting certain ASP.NET page and control directives globally for all pages and controls in the scope of the configuration file. This includes the @ Page directive, the @ Import directive through the Namespaces collection property, and the @ Register directive through the Controls collection property. It also provides support for mapping tag types to other tag types at run time through the TagMapping collection property.

Directives specify settings used by the page and user-control compilers when they process ASP.NET Web Forms page (.aspx) and user control (.ascx) files.

This example demonstrates how to specify values declaratively for several attributes of the pages section, which can also be accessed as members of the PagesSection class.

The following configuration file example shows how to specify values declaratively for the pages section.

  <pages buffer="true" 
    maintainScrollPositionOnPostBack = "False"
    viewStateEncryptionMode = "Auto">
      <add namespace="System" />
      <add namespace="System.Collections" />
      <add namespace="System.Collections.Specialized" />
      <add namespace="System.ComponentModel" />
      <add namespace="System.Configuration" />
      <add namespace="System.Web" />
      <clear />
      <remove tagPrefix="MyTags" />
      <!—- Searches all linked assemblies for the namespace -->
      <add tagPrefix="MyTags1" namespace=" MyNameSpace "/>
      <!-- Uses a specified assembly -->
      <add tagPrefix="MyTags2" namespace="MyNameSpace" 
      <!-- Uses the specified source for the user control -->
      <add tagprefix="MyTags3" tagname="MyCtrl"     
      <clear />
          MSPS.Web.dll, Version=''" 
      <remove tagTypeName="SomeOtherNS.Class, Assemblyname" />

The following code example demonstrates how to use the PagesSection class.

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Web.Configuration;
using System.Web.UI;

namespace Samples.Aspnet.SystemWebConfiguration
  class UsingPagesSection
    public static void Main()
        // Get the Web application configuration.
        Configuration configuration =

        // Get the section.
        PagesSection pagesSection =

        // Get the AutoImportVBNamespace property.
        Console.WriteLine("AutoImportVBNamespace: '{0}'",

        // Set the AutoImportVBNamespace property.
        pagesSection.Namespaces.AutoImportVBNamespace = true;

        // Get all current Namespaces in the collection. 
        for (int i = 0; i < pagesSection.Namespaces.Count; i++)
              "Namespaces {0}: '{1}'", i,

        // Create a new NamespaceInfo object.
        System.Web.Configuration.NamespaceInfo namespaceInfo =
            new System.Web.Configuration.NamespaceInfo("System");

        // Set the Namespace property.
        namespaceInfo.Namespace = "System.Collections";

        // Execute the Add Method.

        // Add a NamespaceInfo object using a constructor.
            new System.Web.Configuration.NamespaceInfo(

        // Execute the RemoveAt method.

        // Execute the Clear method.

        // Execute the Remove method.

        // Get the current AutoImportVBNamespace property value.
            "Current AutoImportVBNamespace value: '{0}'",

        // Set the AutoImportVBNamespace property to false.
        pagesSection.Namespaces.AutoImportVBNamespace = false;

        // Get the current PageParserFilterType property value.
            "Current PageParserFilterType value: '{0}'",

        // Set the PageParserFilterType property to 
        // "MyNameSpace.AllowOnlySafeControls".
        pagesSection.PageParserFilterType =

        // Get the current Theme property value.
            "Current Theme value: '{0}'",

        // Set the Theme property to "MyCustomTheme".
        pagesSection.Theme = "MyCustomTheme";

        // Get the current EnableViewState property value.
            "Current EnableViewState value: '{0}'",

        // Set the EnableViewState property to false.
        pagesSection.EnableViewState = false;

        // Get the current CompilationMode property value.
            "Current CompilationMode value: '{0}'",

        // Set the CompilationMode property to CompilationMode.Always.
        pagesSection.CompilationMode = CompilationMode.Always;

        // Get the current ValidateRequest property value.
            "Current ValidateRequest value: '{0}'",

        // Set the ValidateRequest property to true.
        pagesSection.ValidateRequest = true;

        // Get the current EnableViewStateMac property value.
            "Current EnableViewStateMac value: '{0}'",

        // Set the EnableViewStateMac property to true.
        pagesSection.EnableViewStateMac = true;

        // Get the current AutoEventWireup property value.
            "Current AutoEventWireup value: '{0}'",

        // Set the AutoEventWireup property to false.
        pagesSection.AutoEventWireup = false;

        // Get the current MaxPageStateFieldLength property value.
            "Current MaxPageStateFieldLength value: '{0}'",

        // Set the MaxPageStateFieldLength property to 4098.
        pagesSection.MaxPageStateFieldLength = 4098;

        // Get the current UserControlBaseType property value.
            "Current UserControlBaseType value: '{0}'",

        // Set the UserControlBaseType property to 
        // "MyNameSpace.MyCustomControlBaseType".
        pagesSection.UserControlBaseType =

        // Get all current Controls in the collection. 
        for (int i = 0; i < pagesSection.Controls.Count; i++)
          Console.WriteLine("Control {0}:", i);
          Console.WriteLine("  TagPrefix = '{0}' ",
          Console.WriteLine("  TagName = '{0}' ",
          Console.WriteLine("  Source = '{0}' ",
          Console.WriteLine("  Namespace = '{0}' ",
          Console.WriteLine("  Assembly = '{0}' ",

        // Create a new TagPrefixInfo object.
        System.Web.Configuration.TagPrefixInfo tagPrefixInfo =
            new System.Web.Configuration.TagPrefixInfo("MyCtrl", "MyNameSpace", "MyAssembly", "MyControl", "MyControl.ascx");

        // Execute the Add Method.

        // Add a TagPrefixInfo object using a constructor.
            new System.Web.Configuration.TagPrefixInfo(
            "MyCtrl", "MyNameSpace", "MyAssembly", "MyControl",

        // Get the current StyleSheetTheme property value.
            "Current StyleSheetTheme value: '{0}'",

        // Set the StyleSheetTheme property.
        pagesSection.StyleSheetTheme =

        // Get the current EnableSessionState property value.
            "Current EnableSessionState value: '{0}'",

        // Set the EnableSessionState property to 
        // PagesEnableSessionState.ReadOnly.
        pagesSection.EnableSessionState =

        // Get the current MasterPageFile property value.
            "Current MasterPageFile value: '{0}'",

        // Set the MasterPageFile property to "MyMasterPage.ascx".
        pagesSection.MasterPageFile = "MyMasterPage.ascx";

        // Get the current Buffer property value.
            "Current Buffer value: '{0}'", pagesSection.Buffer);

        // Set the Buffer property to true.
        pagesSection.Buffer = true;

        // Get all current TagMappings in the collection. 
        for (int i = 0; i < pagesSection.TagMapping.Count; i++)
          Console.WriteLine("TagMapping {0}:", i);
          Console.WriteLine("  TagTypeName = '{0}'",
          Console.WriteLine("  MappedTagTypeName = '{0}'",

        // Add a TagMapInfo object using a constructor.
            new System.Web.Configuration.TagMapInfo(
            "MyNameSpace.MyControl", "MyNameSpace.MyOtherControl"));

        // Get the current PageBaseType property value.
            "Current PageBaseType value: '{0}'",

        // Set the PageBaseType property to 
        // "MyNameSpace.MyCustomPagelBaseType".
        pagesSection.PageBaseType =

        // Get the current SmartNavigation property value.
            "Current SmartNavigation value: '{0}'",

        // Set the SmartNavigation property to true.
        pagesSection.SmartNavigation = true;

        // Update if not locked. 
        if (!pagesSection.SectionInformation.IsLocked)
          Console.WriteLine("** Configuration updated.");
          Console.WriteLine("** Could not update, section is locked.");
      catch (System.Exception e)
        // Unknown error.
        Console.WriteLine("A unknown exception detected in" +
          "UsingPagesSection Main.");
  } // UsingPagesSection class end.
} // Samples.Aspnet.SystemWebConfiguration namespace end.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2015 Microsoft