This topic has not yet been rated - Rate this topic

ConfigurationAttribute Class

IIS 7.0

Represents a single property in a configuration element.

System..::..Object
  Microsoft.Web.Administration..::..ConfigurationAttribute

Namespace:  Microsoft.Web.Administration
Assembly:  Microsoft.Web.Administration (in Microsoft.Web.Administration.dll)
public class ConfigurationAttribute

The ConfigurationAttribute type exposes the following members.

  Name Description
Public property IsInheritedFromDefaultValue Gets a value indicating whether the attribute value is the default value.
Public property IsProtected Gets a value indicating whether the attribute value is encrypted.
Public property Name Gets the name of the configuration attribute.
Public property Schema Gets the schema object that is used for the configuration attribute.
Public property Value Gets the value of the configuration attribute.
Top
  Name Description
Public method Delete Deletes the configuration attribute from the configuration section.
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetMetadata Gets attribute metadata from the IIS 7 configuration system.
Public method GetType (Inherited from Object.)
Protected method MemberwiseClone (Inherited from Object.)
Public method SetMetadata Sets attribute metadata in the IIS 7 configuration system.
Public method ToString (Inherited from Object.)
Top

The following example displays a few property values for the ConfigurationAttribute object. The example sets the metadata, commits the changes to the ApplicationHost.config file, and then gets the metadata.


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

namespace AdministrationSnippets
{
    public class SnippetConfigurationAttribute
    {
        public void GetConfigurationAttribute()
        {
            ServerManager manager = new ServerManager();
            Configuration config = manager.GetApplicationHostConfiguration();
            ConfigurationSection configSection =
                config.GetSection("system.web/anonymousIdentification");

            ConfigurationAttributeCollection configAttributeCollection =
                configSection.Attributes;

            ConfigurationAttribute attribute = configAttributeCollection[1];
            // Use any of the following encryption providers.
            // attribute.SetMetadata("encryptionProvider", "IISWASOnlyRsaProvider");
            // attribute.SetMetadata("encryptionProvider", "AesProvider");
            attribute.SetMetadata("encryptionProvider", "IISWASOnlyAesProvider");

            // Commit the changes to applicationHost.config
            manager.CommitChanges();
            // Get the attributes again, after the commit changes.
            Configuration config2 = manager.GetApplicationHostConfiguration();
            configSection = config2.GetSection("system.web/anonymousIdentification");
            configAttributeCollection = configSection.Attributes;
            Console.WriteLine("There are " +
                configAttributeCollection.Count.ToString() +
                " Configuration attributes.");
            attribute = configAttributeCollection[1];
            Console.WriteLine("metadata: " +
                attribute.GetMetadata("encryptionProvider"));
            // Display each configuration attribute with properties and metadata.
            foreach (ConfigurationAttribute configAttribute in configAttributeCollection)
            {
                Console.WriteLine("\t{0}\t{1}\t{2}\t{3}",
                     configAttribute.Name,
                     configAttribute.Value,
                     configAttribute.IsProtected,
                     configAttribute.GetMetadata("encryptionProvider"));
            }
        }
    }
}


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ