ConfigurationSection.SetAllowDefinition Method

Sets the allowDefinition attribute for a configuration section.

Syntax

ConfigurationSection.SetAllowDefinition(AllowDefinition)  
ConfigurationSection.SetAllowDefinition(AllowDefinition);  

Parameters

Name Definition
AllowDefinition A string variable that specifies the value to which the allowDefinition attribute will be set. The possible attribute values are listed later in the Remarks section.

Return Value

This method does not return a value.

Remarks

allowDefinition attributes specify where in the configuration hierarchy values may be set for a given configuration section. These attributes are specified in the <configSections> section of the ApplicationHost.config file.

Because SetAllowDefinition is a static method, you should call it by getting a class object, as in the following example.

' Correct syntax:  
Set oAnonAuth = oWebAdmin.Get("AnonymousAuthenticationSection")  
oAnonAuth.SetAllowDefinition "MachineOnly"  

The following syntax fails because it tries to call SetAllowDefinition on a concrete instance of the Site class. The call to the method will cause an "SWbemObjectEx: Not found" error.

' Incorrect syntax:  
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")  
oSite.GetSection "AnonymousAuthenticationSection", oAnonAuth  
oAnonAuth.SetAllowDefinition "MachineOnly"  

The following table lists the possible values for the allowDefinition attribute.

Keyword Description
Everywhere The section can be set anywhere in the hierarchy.
MachineOnly The section can be set only in the Machine.config file. Note: The default location for the Machine.config file is %systemroot% Microsoft.NET\Framework\<version>\config\.
MachineToWebRoot The section can be set only in the Machine.config file or the root Web.config file. Note: The default location for the root Web.config file is %systemroot% Microsoft.NET\Framework\<version>\config\.
AppHostOnly The section can be set only in the ApplicationHost.config file.
MachineToApplication The section can be set only at the global level. For .NET Framework sections, the global level is the root Web.config or Machine.config file; for IIS sections, it is the ApplicationHost.config file; and for applications, it is the Web.config file for the root application.

Example

The following example sets the allowDefinition attribute for the Anonymous authentication configuration section.

' Get the WebAdministration namespace.  
Set oWebAdmin = GetObject( _  
    "winmgmts:root\WebAdministration")  
  
' Get the AnonymousAuthenticationSection.  
Set oAnonAuth = oWebAdmin.Get( _  
    "AnonymousAuthenticationSection")  
  
' Set the AllowDefinition attribute.  
oAnonAuth.SetAllowDefinition "MachineToApplication"  
  

Requirements

Type Description
Client - IIS 7.0 on Windows Vista
- IIS 7.5 on Windows 7
- IIS 8.0 on Windows 8
- IIS 10.0 on Windows 10
Server - IIS 7.0 on Windows Server 2008
- IIS 7.5 on Windows Server 2008 R2
- IIS 8.0 on Windows Server 2012
- IIS 8.5 on Windows Server 2012 R2
- IIS 10.0 on Windows Server 2016
Product - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
MOF file WebAdministration.mof

See Also

AnonymousAuthenticationSection Class
ConfigurationSection Class
ConfigurationSection.GetAllowDefinition Method