共用方式為


ConfigurationAttribute 類別

定義

表示組態專案中的單一屬性。

public ref class ConfigurationAttribute
public class ConfigurationAttribute
type ConfigurationAttribute = class
Public Class ConfigurationAttribute
繼承
ConfigurationAttribute

範例

下列範例會顯示 物件的 ConfigurationAttribute 幾個屬性值。 此範例會設定中繼資料、認可ApplicationHost.config檔案的變更,然後取得中繼資料。

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"));
            }
        }
    }
}

屬性

IsInheritedFromDefaultValue

取得值,指出屬性值是否為預設值。

IsProtected

取得值,指出屬性值是否加密。

Name

取得組態屬性的名稱。

Schema

取得用於組態屬性的架構物件。

Value

取得組態屬性的值。

方法

Delete()

從組態區段刪除組態屬性。

GetMetadata(String)

從 IIS 7 組態系統取得屬性中繼資料。

SetMetadata(String, Object)

設定 IIS 7 組態系統中的屬性中繼資料。

適用於