PagesSection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供對於組態檔 pages 區段的程式設計存取。 此類別無法獲得繼承。
public ref class PagesSection sealed : System::Configuration::ConfigurationSection
public sealed class PagesSection : System.Configuration.ConfigurationSection
type PagesSection = class
inherit ConfigurationSection
Public NotInheritable Class PagesSection
Inherits ConfigurationSection
- 繼承
範例
這個範例示範如何針對 區段的 pages 數個屬性以宣告方式指定值,而這個屬性也可以當做 類別的成員 PagesSection 存取。
下列組態檔範例示範如何以宣告方式指定 頁面 區段的值。
<system.web>
<pages buffer="true"
enableSessionState="true"
enableViewState="true"
enableViewStateMac="true"
autoEventWireup="true"
validateRequest="true"
asyncTimeout="45"
maintainScrollPositionOnPostBack = "False"
viewStateEncryptionMode = "Auto">
<namespaces>
<add namespace="System" />
<add namespace="System.Collections" />
<add namespace="System.Collections.Specialized" />
<add namespace="System.ComponentModel" />
<add namespace="System.Configuration" />
<add namespace="System.Web" />
</namespaces>
<controls>
<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"
assembly="MyAssembly"/>
<!-- Uses the specified source for the user control -->
<add tagprefix="MyTags3" tagname="MyCtrl"
src="MyControl.ascx"/>
</controls>
<tagMapping>
<clear />
<add
tagTypeName=
"System.Web.UI.WebControls.WebParts.WebPartManager"
mappedTagTypeName=
"Microsoft.Sharepoint.WebPartPartManager,
MSPS.Web.dll, Version='2.0.0.0'"
/>
<remove tagTypeName="SomeOtherNS.Class, Assemblyname" />
</tagMapping>
</pages>
</system.web>
下列程式代碼範例示範如何使用 類別 PagesSection 。
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()
{
try
{
// Get the Web application configuration.
Configuration configuration =
WebConfigurationManager.OpenWebConfiguration("");
// Get the section.
PagesSection pagesSection =
(PagesSection)configuration.GetSection("system.web/pages");
// Get the AutoImportVBNamespace property.
Console.WriteLine("AutoImportVBNamespace: '{0}'",
pagesSection.Namespaces.AutoImportVBNamespace.ToString());
// Set the AutoImportVBNamespace property.
pagesSection.Namespaces.AutoImportVBNamespace = true;
// Get all current Namespaces in the collection.
for (int i = 0; i < pagesSection.Namespaces.Count; i++)
{
Console.WriteLine(
"Namespaces {0}: '{1}'", i,
pagesSection.Namespaces[i].Namespace);
}
// 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.
pagesSection.Namespaces.Add(namespaceInfo);
// Add a NamespaceInfo object using a constructor.
pagesSection.Namespaces.Add(
new System.Web.Configuration.NamespaceInfo(
"System.Collections.Specialized"));
// Execute the RemoveAt method.
pagesSection.Namespaces.RemoveAt(0);
// Execute the Clear method.
pagesSection.Namespaces.Clear();
// Execute the Remove method.
pagesSection.Namespaces.Remove("System.Collections");
// Get the current AutoImportVBNamespace property value.
Console.WriteLine(
"Current AutoImportVBNamespace value: '{0}'",
pagesSection.Namespaces.AutoImportVBNamespace);
// Set the AutoImportVBNamespace property to false.
pagesSection.Namespaces.AutoImportVBNamespace = false;
// Get the current PageParserFilterType property value.
Console.WriteLine(
"Current PageParserFilterType value: '{0}'",
pagesSection.PageParserFilterType);
// Set the PageParserFilterType property to
// "MyNameSpace.AllowOnlySafeControls".
pagesSection.PageParserFilterType =
"MyNameSpace.AllowOnlySafeControls";
// Get the current Theme property value.
Console.WriteLine(
"Current Theme value: '{0}'",
pagesSection.Theme);
// Set the Theme property to "MyCustomTheme".
pagesSection.Theme = "MyCustomTheme";
// Get the current EnableViewState property value.
Console.WriteLine(
"Current EnableViewState value: '{0}'",
pagesSection.EnableViewState);
// Set the EnableViewState property to false.
pagesSection.EnableViewState = false;
// Get the current CompilationMode property value.
Console.WriteLine(
"Current CompilationMode value: '{0}'",
pagesSection.CompilationMode);
// Set the CompilationMode property to CompilationMode.Always.
pagesSection.CompilationMode = CompilationMode.Always;
// Get the current ValidateRequest property value.
Console.WriteLine(
"Current ValidateRequest value: '{0}'",
pagesSection.ValidateRequest);
// Set the ValidateRequest property to true.
pagesSection.ValidateRequest = true;
// Get the current EnableViewStateMac property value.
Console.WriteLine(
"Current EnableViewStateMac value: '{0}'",
pagesSection.EnableViewStateMac);
// Set the EnableViewStateMac property to true.
pagesSection.EnableViewStateMac = true;
// Get the current AutoEventWireup property value.
Console.WriteLine(
"Current AutoEventWireup value: '{0}'",
pagesSection.AutoEventWireup);
// Set the AutoEventWireup property to false.
pagesSection.AutoEventWireup = false;
// Get the current MaxPageStateFieldLength property value.
Console.WriteLine(
"Current MaxPageStateFieldLength value: '{0}'",
pagesSection.MaxPageStateFieldLength);
// Set the MaxPageStateFieldLength property to 4098.
pagesSection.MaxPageStateFieldLength = 4098;
// Get the current UserControlBaseType property value.
Console.WriteLine(
"Current UserControlBaseType value: '{0}'",
pagesSection.UserControlBaseType);
// Set the UserControlBaseType property to
// "MyNameSpace.MyCustomControlBaseType".
pagesSection.UserControlBaseType =
"MyNameSpace.MyCustomControlBaseType";
// 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}' ",
pagesSection.Controls[i].TagPrefix);
Console.WriteLine(" TagName = '{0}' ",
pagesSection.Controls[i].TagName);
Console.WriteLine(" Source = '{0}' ",
pagesSection.Controls[i].Source);
Console.WriteLine(" Namespace = '{0}' ",
pagesSection.Controls[i].Namespace);
Console.WriteLine(" Assembly = '{0}' ",
pagesSection.Controls[i].Assembly);
}
// 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.
pagesSection.Controls.Add(tagPrefixInfo);
// Add a TagPrefixInfo object using a constructor.
pagesSection.Controls.Add(
new System.Web.Configuration.TagPrefixInfo(
"MyCtrl", "MyNameSpace", "MyAssembly", "MyControl",
"MyControl.ascx"));
// Get the current StyleSheetTheme property value.
Console.WriteLine(
"Current StyleSheetTheme value: '{0}'",
pagesSection.StyleSheetTheme);
// Set the StyleSheetTheme property.
pagesSection.StyleSheetTheme =
"MyCustomStyleSheetTheme";
// Get the current EnableSessionState property value.
Console.WriteLine(
"Current EnableSessionState value: '{0}'",
pagesSection.EnableSessionState);
// Set the EnableSessionState property to
// PagesEnableSessionState.ReadOnly.
pagesSection.EnableSessionState =
PagesEnableSessionState.ReadOnly;
// Get the current MasterPageFile property value.
Console.WriteLine(
"Current MasterPageFile value: '{0}'",
pagesSection.MasterPageFile);
// Set the MasterPageFile property to "MyMasterPage.ascx".
pagesSection.MasterPageFile = "MyMasterPage.ascx";
// Get the current Buffer property value.
Console.WriteLine(
"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}'",
pagesSection.TagMapping[i].TagType);
Console.WriteLine(" MappedTagTypeName = '{0}'",
pagesSection.TagMapping[i].MappedTagType);
}
// Add a TagMapInfo object using a constructor.
pagesSection.TagMapping.Add(
new System.Web.Configuration.TagMapInfo(
"MyNameSpace.MyControl", "MyNameSpace.MyOtherControl"));
// Get the current PageBaseType property value.
Console.WriteLine(
"Current PageBaseType value: '{0}'",
pagesSection.PageBaseType);
// Set the PageBaseType property to
// "MyNameSpace.MyCustomPagelBaseType".
pagesSection.PageBaseType =
"MyNameSpace.MyCustomPagelBaseType";
// Get the current SmartNavigation property value.
Console.WriteLine(
"Current SmartNavigation value: '{0}'",
pagesSection.SmartNavigation);
// Set the SmartNavigation property to true.
pagesSection.SmartNavigation = true;
// Update if not locked.
if (!pagesSection.SectionInformation.IsLocked)
{
configuration.Save();
Console.WriteLine("** Configuration updated.");
}
else
{
Console.WriteLine("** Could not update, section is locked.");
}
}
catch (System.Exception e)
{
// Unknown error.
Console.WriteLine("A unknown exception detected in" +
"UsingPagesSection Main.");
Console.WriteLine(e);
}
Console.ReadLine();
}
} // UsingPagesSection class end.
} // Samples.Aspnet.SystemWebConfiguration namespace end.
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Configuration
Imports System.Web.Configuration
Imports System.Web.UI
Namespace Samples.Aspnet.SystemWebConfiguration
Class UsingPagesSection
Public Shared Sub Main()
Try
' Get the Web application configuration.
Dim configuration As System.Configuration.Configuration = _
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("")
' Get the section.
Dim pagesSection As System.Web.Configuration.PagesSection = _
CType(configuration.GetSection("system.web/pages"), _
System.Web.Configuration.PagesSection)
' Get the AutoImportVBNamespace property.
Console.WriteLine( _
"AutoImportVBNamespace: '{0}'", _
pagesSection.Namespaces.AutoImportVBNamespace)
' Set the AutoImportVBNamespace property.
pagesSection.Namespaces.AutoImportVBNamespace = True
' Get all current Namespaces in the collection.
Dim i As Int16
For i = 0 To pagesSection.Namespaces.Count - 1
Console.WriteLine( _
"Namespaces {0}: '{1}'", i, _
pagesSection.Namespaces(i).Namespace)
Next
' Create a new NamespaceInfo object.
Dim namespaceInfo As System.Web.Configuration.NamespaceInfo = _
New System.Web.Configuration.NamespaceInfo("System")
' Set the Namespace property.
namespaceInfo.Namespace = "System.Collections"
' Execute the Add Method.
pagesSection.Namespaces.Add(namespaceInfo)
' Add a NamespaceInfo object using a constructor.
pagesSection.Namespaces.Add( _
New System.Web.Configuration.NamespaceInfo( _
"System.Collections.Specialized"))
' Execute the RemoveAt method.
pagesSection.Namespaces.RemoveAt(0)
' Execute the Clear method.
pagesSection.Namespaces.Clear()
' Execute the Remove method.
pagesSection.Namespaces.Remove("System.Collections")
' Get the current AutoImportVBNamespace property value.
Console.WriteLine( _
"Current AutoImportVBNamespace value: '{0}'", _
pagesSection.Namespaces.AutoImportVBNamespace)
' Set the AutoImportVBNamespace property to false.
pagesSection.Namespaces.AutoImportVBNamespace = False
' Get the current PageParserFilterType property value.
Console.WriteLine( _
"Current PageParserFilterType value: '{0}'", _
pagesSection.PageParserFilterType)
' Set the PageParserFilterType property to
' "MyNameSpace.AllowOnlySafeControls".
pagesSection.PageParserFilterType = _
"MyNameSpace.AllowOnlySafeControls"
' Get the current Theme property value.
Console.WriteLine( _
"Current Theme value: '{0}'", pagesSection.Theme)
' Set the Theme property to "MyCustomTheme".
pagesSection.Theme = "MyCustomTheme"
' Get the current EnableViewState property value.
Console.WriteLine( _
"Current EnableViewState value: '{0}'", _
pagesSection.EnableViewState)
' Set the EnableViewState property to false.
pagesSection.EnableViewState = False
' Get the current CompilationMode property value.
Console.WriteLine( _
"Current CompilationMode value: '{0}'", _
pagesSection.CompilationMode)
' Set the CompilationMode property to CompilationMode.Always.
pagesSection.CompilationMode = CompilationMode.Always
' Get the current ValidateRequest property value.
Console.WriteLine( _
"Current ValidateRequest value: '{0}'", _
pagesSection.ValidateRequest)
' Set the ValidateRequest property to true.
pagesSection.ValidateRequest = True
' Get the current EnableViewStateMac property value.
Console.WriteLine( _
"Current EnableViewStateMac value: '{0}'", _
pagesSection.EnableViewStateMac)
' Set the EnableViewStateMac property to true.
pagesSection.EnableViewStateMac = True
' Get the current AutoEventWireup property value.
Console.WriteLine( _
"Current AutoEventWireup value: '{0}'", _
pagesSection.AutoEventWireup)
' Set the AutoEventWireup property to false.
pagesSection.AutoEventWireup = False
' Get the current MaxPageStateFieldLength property value.
Console.WriteLine( _
"Current MaxPageStateFieldLength value: '{0}'", _
pagesSection.MaxPageStateFieldLength)
' Set the MaxPageStateFieldLength property to 4098.
pagesSection.MaxPageStateFieldLength = 4098
' Get the current UserControlBaseType property value.
Console.WriteLine( _
"Current UserControlBaseType value: '{0}'", _
pagesSection.UserControlBaseType)
' Set the UserControlBaseType property to
' "MyNameSpace.MyCustomControlBaseType".
pagesSection.UserControlBaseType = _
"MyNameSpace.MyCustomControlBaseType"
' Get all current Controls in the collection.
Dim j As Int32
For j = 0 To pagesSection.Controls.Count - 1
Console.WriteLine("Control {0}:", j)
Console.WriteLine(" TagPrefix = '{0}' ", _
pagesSection.Controls(j).TagPrefix)
Console.WriteLine(" TagName = '{0}' ", _
pagesSection.Controls(j).TagName)
Console.WriteLine(" Source = '{0}' ", _
pagesSection.Controls(j).Source)
Console.WriteLine(" Namespace = '{0}' ", _
pagesSection.Controls(j).Namespace)
Console.WriteLine(" Assembly = '{0}' ", _
pagesSection.Controls(j).Assembly)
Next
' Create a new TagPrefixInfo object.
Dim tagPrefixInfo As System.Web.Configuration.TagPrefixInfo = _
New System.Web.Configuration.TagPrefixInfo("MyCtrl", "MyNameSpace", "MyAssembly", "MyControl", "MyControl.ascx")
' Execute the Add Method.
pagesSection.Controls.Add(tagPrefixInfo)
' Add a TagPrefixInfo object using a constructor.
pagesSection.Controls.Add( _
New System.Web.Configuration.TagPrefixInfo( _
"MyCtrl", "MyNameSpace", "MyAssembly", "MyControl", _
"MyControl.ascx"))
' Get the current StyleSheetTheme property value.
Console.WriteLine( _
"Current StyleSheetTheme value: '{0}'", _
pagesSection.StyleSheetTheme)
' Set the StyleSheetTheme property to
' "MyCustomStyleSheetTheme".
pagesSection.StyleSheetTheme = "MyCustomStyleSheetTheme"
' Get the current EnableSessionState property value.
Console.WriteLine( _
"Current EnableSessionState value: '{0}'", pagesSection.EnableSessionState)
' Set the EnableSessionState property to
' PagesEnableSessionState.ReadOnly.
pagesSection.EnableSessionState = PagesEnableSessionState.ReadOnly
' Get the current MasterPageFile property value.
Console.WriteLine( _
"Current MasterPageFile value: '{0}'", _
pagesSection.MasterPageFile)
' Set the MasterPageFile property to "MyMasterPage.ascx".
pagesSection.MasterPageFile = "MyMasterPage.ascx"
' Get the current Buffer property value.
Console.WriteLine( _
"Current Buffer value: '{0}'", pagesSection.Buffer)
' Set the Buffer property to true.
pagesSection.Buffer = True
' Get all current TagMappings in the collection.
Dim k As Int32
For k = 1 To pagesSection.TagMapping.Count
Console.WriteLine("TagMapping {0}:", i)
Console.WriteLine(" TagTypeName = '{0}'", _
pagesSection.TagMapping(k).TagType)
Console.WriteLine(" MappedTagTypeName = '{0}'", _
pagesSection.TagMapping(k).MappedTagType)
Next
' Add a TagMapInfo object using a constructor.
pagesSection.TagMapping.Add( _
New System.Web.Configuration.TagMapInfo( _
"MyNameSpace.MyControl", "MyNameSpace.MyOtherControl"))
' Get the current PageBaseType property value.
Console.WriteLine( _
"Current PageBaseType value: '{0}'", pagesSection.PageBaseType)
' Set the PageBaseType property to
' "MyNameSpace.MyCustomPagelBaseType".
pagesSection.PageBaseType = "MyNameSpace.MyCustomPagelBaseType"
' Get the current SmartNavigation property value.
Console.WriteLine( _
"Current SmartNavigation value: '{0}'", pagesSection.SmartNavigation)
' Set the SmartNavigation property to true.
pagesSection.SmartNavigation = True
' Update if not locked.
If Not pagesSection.SectionInformation.IsLocked Then
configuration.Save()
Console.WriteLine("** Configuration updated.")
Else
Console.WriteLine("** Could not update, section is locked.")
End If
Catch e As System.Exception
' Unknown error.
Console.WriteLine("A unknown exception detected in " & _
"UsingPagesSection Main.")
Console.WriteLine(e)
End Try
Console.ReadLine()
End Sub
End Class
End Namespace ' Samples.Aspnet.SystemWebConfiguration
備註
類別 PagesSection 可讓您以程式設計方式存取和修改組態檔 頁面區 段的內容。 此組態區段支援全域設定組態檔範圍內所有頁面和控件的特定 ASP.NET 頁面和控件指示詞。
@ Page這包括 指示詞、@ Import透過集合屬性的 Namespaces 指示詞,以及透過集合屬性的 @ RegisterControls 指示詞。 它也支援透過集合屬性,在運行時間 TagMapping 將標記類型對應至其他標記類型。
指示詞會指定頁面和使用者控件編譯程式處理網頁 ASP.NET 網頁 (.aspx) 和使用者控件 (.ascx) 檔案時所使用的設定。
建構函式
| 名稱 | Description |
|---|---|
| PagesSection() |
使用預設值初始化 PagesSection 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| AsyncTimeout |
取得或設定值,表示在進行非同步的頁面處理時,等待非同步處理常式完成的秒數。 |
| AutoEventWireup |
取得或設定值,指出 ASP.NET 頁面的事件是否自動連接到事件處理函式。 |
| Buffer |
取得或設定值,指出 .aspx 頁面和 .ascx 控制項是否使用回應緩衝。 |
| ClientIDMode |
取得或設定用來產生控制項識別項的預設演算法。 |
| CompilationMode |
取得或設定值,決定如何編譯 .aspx 頁面和 .ascx 控制項。 |
| ControlRenderingCompatibilityVersion |
取得或設定值,這個值會指定將與任何呈現 HTML 相容的 ASP.NET 版本。 |
| Controls |
取得 TagPrefixInfo 物件的集合。 |
| CurrentConfiguration |
取得最上層 Configuration 執行個體的參考,這個執行個體表示目前 ConfigurationElement 執行個體所屬的組態階層架構。 (繼承來源 ConfigurationElement) |
| ElementInformation |
取得 ElementInformation 物件,其中包含 ConfigurationElement 物件之不可自訂的資訊和功能。 (繼承來源 ConfigurationElement) |
| ElementProperty |
取得表示 ConfigurationElementProperty 物件本身的 ConfigurationElement 物件。 (繼承來源 ConfigurationElement) |
| EnableEventValidation |
取得或設定值,這個值會指定是否啟用事件驗證。 |
| EnableSessionState |
取得或設定值,指定工作階段狀態為啟用、停用或唯讀。 |
| EnableViewState |
取得或設定值,表示檢視狀態為啟用或停用。 |
| EnableViewStateMac |
取得或設定值,指定當頁面從用戶端回傳時,ASP.NET 是否該在頁面的檢視狀態執行訊息驗證碼 (MAC)。 |
| EvaluationContext |
取得 ConfigurationElement 物件的 ContextInformation 物件。 (繼承來源 ConfigurationElement) |
| HasContext |
取得值,指出 CurrentConfiguration 屬性是否為 |
| IgnoreDeviceFilters |
取得 ASP.NET 在呈現網頁時應該要忽略的裝置標籤集合。 |
| Item[ConfigurationProperty] |
取得或設定此組態項目的屬性 (Property) 或屬性 (Attribute)。 (繼承來源 ConfigurationElement) |
| Item[String] |
取得或設定此一組態項目的屬性或子項目。 (繼承來源 ConfigurationElement) |
| LockAllAttributesExcept |
取得已鎖定屬性的集合。 (繼承來源 ConfigurationElement) |
| LockAllElementsExcept |
取得已鎖定項目的集合。 (繼承來源 ConfigurationElement) |
| LockAttributes |
取得已鎖定屬性的集合。 (繼承來源 ConfigurationElement) |
| LockElements |
取得已鎖定項目的集合。 (繼承來源 ConfigurationElement) |
| LockItem |
取得或設定值,指出此項目是否已被鎖定。 (繼承來源 ConfigurationElement) |
| MaintainScrollPositionOnPostBack |
取得或設定值,指出是否該在從伺服器回傳時,維持頁面捲動位置。 |
| MasterPageFile |
取得或設定應用程式主版頁面的參考。 |
| MaxPageStateFieldLength |
取得或設定單一檢視狀態欄位可以包含的最多字元數。 |
| Namespaces |
取得 NamespaceInfo 物件的集合。 |
| PageBaseType |
取得或設定值,指定 .aspx 頁面預設繼承的程式碼後置 (Code-Behind) 類別。 |
| PageParserFilterType |
取得或設定指定剖析器篩選器型別的值。 |
| Properties |
取得屬性的集合。 (繼承來源 ConfigurationElement) |
| RenderAllHiddenFieldsAtTopOfForm |
取得或設定值,這個值會指定系統產生的所有隱藏欄位是否都要呈現在表單頂端。 |
| SectionInformation |
取得 SectionInformation 物件,該物件包含 ConfigurationSection 物件之不可自訂的資訊和功能。 (繼承來源 ConfigurationSection) |
| SmartNavigation |
取得或設定值,指出是否啟用智慧巡覽。 |
| StyleSheetTheme |
取得或設定 ASP.NET 樣式表主題的名稱。 |
| TagMapping |
取得 TagMapInfo 物件的集合。 |
| Theme |
取得或設定 ASP.NET 頁面主題的名稱。 |
| UserControlBaseType |
取得或設定值,指定使用者控制項預設繼承的程式碼後置類別。 |
| ValidateRequest |
取得或設定值,決定 ASP.NET 是否對來自瀏覽器的輸入檢查危險值。 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。 |
| ViewStateEncryptionMode |
取得或設定 ASP.NET 用來在維護 |