Export (0) Print
Expand All

ConfigurationAttribute Class

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.

  NameDescription
Public propertyIsInheritedFromDefaultValueGets a value indicating whether the attribute value is the default value.
Public propertyIsProtectedGets a value indicating whether the attribute value is encrypted.
Public propertyNameGets the name of the configuration attribute.
Public propertySchemaGets the schema object that is used for the configuration attribute.
Public propertyValueGets the value of the configuration attribute.
Top

  NameDescription
Public methodDeleteDeletes the configuration attribute from the configuration section.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetMetadataGets attribute metadata from the IIS 7 configuration system.
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodSetMetadataSets attribute metadata in the IIS 7 configuration system.
Public methodToString (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.

Community Additions

ADD
Show:
© 2014 Microsoft