SectionDefinition.AllowDefinition 属性

定义

获取或设置一个值,该值指示配置节的有效配置路径位置。

public:
 property System::String ^ AllowDefinition { System::String ^ get(); void set(System::String ^ value); };
public string AllowDefinition { get; set; }
member this.AllowDefinition : string with get, set
Public Property AllowDefinition As String

属性值

配置路径位置。

示例

以下示例演示 了 AllowDefinition 属性。


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
using Microsoft.Web.Management;

namespace AdministrationSnippets
{
    public class AdministrationSectionDefinition
    {
        // List all configuration sections in applicationHost.config
        public void ShowAllSections()
        {
            ServerManager manager = new ServerManager();
            SectionGroup rootGroup = 
                manager.GetApplicationHostConfiguration().RootSectionGroup;
            ShowGroup(rootGroup, -1);

        }

        private void ShowGroup(SectionGroup group, int indentLevel)
        {
            Console.Write("".PadLeft(++indentLevel, ' '));
            string grpName = String.IsNullOrEmpty(group.Name) ? "{root}" : group.Name;
            Console.WriteLine("+ Section Group: {0}; Sub-groups: {1}; Sections: {2}",
                grpName, group.SectionGroups.Count, group.Sections.Count);

            foreach (SectionGroup grp in group.SectionGroups)
            {
                ShowGroup(grp, indentLevel);
            }

            string path = String.Concat(group.Name, "/");

            foreach (SectionDefinition def in group.Sections)
            {
                Console.Write("".PadLeft(indentLevel, ' '));
                Console.WriteLine("|_Name:                {0}", String.Concat(path,def.Name));
                Console.Write("".PadLeft(indentLevel, ' '));
                Console.WriteLine("|_AllowDefinition:     {0}", def.AllowDefinition);
                Console.Write("".PadLeft(indentLevel, ' '));
                Console.WriteLine("|_AllowLocation:       {0}", def.AllowLocation);
                Console.Write("".PadLeft(indentLevel, ' '));
                Console.WriteLine("|_OverrideModeDefault: {0}", def.OverrideModeDefault);
                Console.Write("".PadLeft(indentLevel, ' '));
                Console.WriteLine("|_Type:                {0}\r\n", 
                    String.IsNullOrEmpty(def.Type) ? "null" : def.Type);
            }
        }

    }
}

注解

下表列出了 属性的有效值 AllowDefinition

定义
“无处不在” 可以在任何配置级别中定义 节。 默认值。
“MachineToApplication” 可以在 Machine.config 或 ApplicationHost.config 文件中定义 节。
“MachineOnly” 只能在 Machine.config 文件中定义 节。
“MachineToWebRoot” 可以在 Machine.config、ApplicationHost.config 或 Web.config 文件中定义 节。 Web.config文件存储在网站根目录中。
“AppHostOnly” 只能在 ApplicationHost.config 文件中定义 节。

适用于