MachineKeySection クラス

定義

Windows フォーム認証、ビューステート検証、およびセッション状態のアプリケーション分離において、暗号化、復号化、およびメッセージ認証コード (MAC) の各操作を実行する場合に使用されるキー生成とアルゴリズムを制御する構成設定を定義します。 このクラスは継承できません。

public ref class MachineKeySection sealed : System::Configuration::ConfigurationSection
public sealed class MachineKeySection : System.Configuration.ConfigurationSection
type MachineKeySection = class
    inherit ConfigurationSection
Public NotInheritable Class MachineKeySection
Inherits ConfigurationSection
継承

このセクションの例では、 machineKey セクションのいくつかの属性に対して宣言的に値を指定する方法を示します。これは、 クラスの MachineKeySection メンバーとしてアクセスすることもできます。

構成ファイルの次の例は、 machineKey セクションに対して宣言的に値を指定する方法を示しています。

<system.web>  
  <machineKey validationKey="AutoGenerate,IsolateApps"   
    decryptionKey="AutoGenerate,IsolateApps"   
    validation="SHA1"/>  
</system.web>  

この例では SHA1 を使用します。 SHA1 との競合問題のため、Microsoft では SHA256 を推奨しています。

次の例では、 クラスをコードで使用する方法を MachineKeySection 示します。

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Configuration;

#endregion

namespace Samples.Aspnet.SystemWebConfiguration
{
  class UsingMachineKeySection
  {
    static void Main(string[] args)
    {
      try
      {
        // Set the path of the config file.
        string configPath = "";

        // Get the Web application configuration object.
        Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);

        // Get the section related object.
        MachineKeySection configSection = 
          (MachineKeySection)config.GetSection("system.web/machineKey");

        // Display title and info.
        Console.WriteLine("ASP.NET Configuration Info");
        Console.WriteLine();

        // Display Config details.
        Console.WriteLine("File Path: {0}",
          config.FilePath);
        Console.WriteLine("Section Path: {0}",
          configSection.SectionInformation.Name);

        // Display ValidationKey property.
        Console.WriteLine("ValidationKey: {0}",
          configSection.ValidationKey);

        // Set ValidationKey property.
        configSection.ValidationKey = "AutoGenerate,IsolateApps";

        // Display DecryptionKey property.
        Console.WriteLine("DecryptionKey: {0}",
          configSection.DecryptionKey);

        // Set DecryptionKey property.
        configSection.DecryptionKey = "AutoGenerate,IsolateApps";

        // Display Validation property.
        Console.WriteLine("Validation: {0}",
          configSection.Validation);

        // Set Validation property.
        configSection.Validation = MachineKeyValidation.HMACSHA256;

        // Update if not locked.
        if (!configSection.SectionInformation.IsLocked)
        {
          config.Save();
          Console.WriteLine("** Configuration updated.");
        }
        else
        {
          Console.WriteLine("** Could not update, section is locked.");
        }
      }

      catch (Exception e)
      {
        // Unknown error.
        Console.WriteLine(e.ToString());
      }

      // Display and wait
      Console.ReadLine();
    }
  }
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration

Namespace Samples.Aspnet.SystemWebConfiguration
  Class UsingMachineKeySection
    Public Shared Sub Main()
      Try
        ' Set the path of the config file.
        Dim configPath As String = ""

        ' Get the Web application configuration object.
        Dim config As System.Configuration.Configuration = _
         System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(configPath)

        ' Get the section related object.
        Dim configSection As System.Web.Configuration.MachineKeySection = _
         CType(config.GetSection("system.web/machineKey"), _
         System.Web.Configuration.MachineKeySection)

        ' Display title and info.
        Console.WriteLine("ASP.NET Configuration Info")
        Console.WriteLine()

        ' Display Config details.
        Console.WriteLine("File Path: {0}", config.FilePath)
        Console.WriteLine("Section Path: {0}", configSection.SectionInformation.Name)

        ' Display ValidationKey property.
        Console.WriteLine("ValidationKey: {0}", _
         configSection.ValidationKey)

        ' Set ValidationKey property.
        configSection.ValidationKey = "AutoGenerate,IsolateApps"

        ' Display DecryptionKey property.
        Console.WriteLine("DecryptionKey: {0}", configSection.DecryptionKey)

        ' Set DecryptionKey property.
        configSection.DecryptionKey = "AutoGenerate,IsolateApps"

        ' Display Validation value.
        Console.WriteLine("Validation: {0}", configSection.Validation)

        ' Set Validation value.
        configSection.Validation = MachineKeyValidation.HMACSHA256

        ' Update if not locked.
        If Not configSection.SectionInformation.IsLocked Then
          config.Save()
          Console.WriteLine("** Configuration updated.")
        Else
          Console.WriteLine("** Could not update, section is locked.")
        End If

      Catch e As Exception
        ' Unknown error.
        Console.WriteLine(e.ToString())
      End Try

      ' Display and wait
      Console.ReadLine()
    End Sub
  End Class
End Namespace

注釈

クラスは MachineKeySection 、構成ファイル内の セクションの MachineKey 内容にプログラムでアクセスして変更する方法を提供します。 セクションはMachineKey、マシン (Machine.config) またはアプリケーション (Web.config) レベルで構成でき、認証、ビューステート検証、およびセッション状態アプリケーションの分離Windows フォーム使用されるキーとアルゴリズムを制御します。 これらの機能のいずれかが Web サーバー (Web ファーム) DecryptionKey のネットワーク全体で動作するには、セクションの 属性と ValidationKey 属性を MachineKey 、有効なキー値と共に明示的かつ同じように構成する必要があります。 この値は AutoGenerate 、コンピューターローカル保護を使用して永続化され、複数のコンピューター間で同じにならない暗号ランダム シークレットに依存するため、Web ファームでは機能しません。

注意 (継承者)

Web ファームのシナリオで必要なように、この構成セクションでキーを指定する場合は、保護された構成を使用してこのセクションを暗号化することをお勧めします。

コンストラクター

MachineKeySection()

既定の設定を使用して MachineKeySection クラスの新しいインスタンスを初期化します。

プロパティ

ApplicationName

アプリケーションの名前を取得または設定します。

CompatibilityMode

.NET Framework Version 2.0 Service Pack 1 より後のリリースで導入された、アップグレードされたビューステートの暗号化方式を使用するかどうかを指定する値を取得または設定します。

CurrentConfiguration

現在の Configuration インスタンスが属している構成階層を表す最上位の ConfigurationElement インスタンスへの参照を取得します。

(継承元 ConfigurationElement)
DataProtectorType

データ プロテクターの型の名前を取得または設定します。 既定値は、Empty です。

Decryption

フォーム認証データの暗号化と復号化に使用される暗号化アルゴリズムを指定します。

DecryptionKey

データの暗号化および復号化に使用されるキー、またはキーが生成されるプロセスを取得または設定します。

ElementInformation

ElementInformation オブジェクトのカスタマイズできない情報と機能を格納する ConfigurationElement オブジェクトを取得します。

(継承元 ConfigurationElement)
ElementProperty

ConfigurationElementProperty オブジェクト自体を表す ConfigurationElement オブジェクトを取得します。

(継承元 ConfigurationElement)
EvaluationContext

ContextInformation オブジェクトの ConfigurationElement オブジェクトを取得します。

(継承元 ConfigurationElement)
HasContext

CurrentConfiguration プロパティが null であるかどうかを示す値を取得します。

(継承元 ConfigurationElement)
Item[ConfigurationProperty]

この構成要素のプロパティまたは属性を取得または設定します。

(継承元 ConfigurationElement)
Item[String]

この構成要素のプロパティ、属性、または子要素を取得または設定します。

(継承元 ConfigurationElement)
LockAllAttributesExcept

ロックされている属性のコレクションを取得します。

(継承元 ConfigurationElement)
LockAllElementsExcept

ロックされている要素のコレクションを取得します。

(継承元 ConfigurationElement)
LockAttributes

ロックされている属性のコレクションを取得します。

(継承元 ConfigurationElement)
LockElements

ロックされている要素のコレクションを取得します。

(継承元 ConfigurationElement)
LockItem

要素がロックされているかどうかを示す値を取得または設定します。

(継承元 ConfigurationElement)
Properties

プロパティのコレクションを取得します。

(継承元 ConfigurationElement)
SectionInformation

SectionInformation オブジェクトのカスタマイズできない情報と機能を格納する ConfigurationSection オブジェクトを取得します。

(継承元 ConfigurationSection)
Validation

フォーム認証とビューステート データの検証に使用されるハッシュ アルゴリズムを指定します。

ValidationAlgorithm

フォーム認証データとビュー ステート データの検証に使用されるアルゴリズムの名前を取得または設定します。

ValidationKey

フォーム認証データとビューステート データの検証に使用されるキー、またはキーが生成されるプロセスを取得または設定します。

メソッド

DeserializeElement(XmlReader, Boolean)

構成ファイルから XML を読み取ります。

(継承元 ConfigurationElement)
DeserializeSection(XmlReader)

構成ファイルから XML を読み取ります。

(継承元 ConfigurationSection)
Equals(Object)

現在の ConfigurationElement インスタンスを、指定したオブジェクトと比較します。

(継承元 ConfigurationElement)
GetHashCode()

現在の ConfigurationElement インスタンスを表す一意の値を取得します。

(継承元 ConfigurationElement)
GetRuntimeObject()

派生クラスでオーバーライドされると、カスタム オブジェクトを返します。

(継承元 ConfigurationSection)
GetTransformedAssemblyString(String)

指定されたアセンブリ名を変換して返します。

(継承元 ConfigurationElement)
GetTransformedTypeString(String)

指定された型名を変換して返します。

(継承元 ConfigurationElement)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
Init()

ConfigurationElement オブジェクトを初期状態に設定します。

(継承元 ConfigurationElement)
InitializeDefault()

ConfigurationElement オブジェクトの既定の値セットを初期化するために使用します。

(継承元 ConfigurationElement)
IsModified()

派生クラスに実装された場合、この構成要素が最後の保存または読み込み以降に変更されたかどうかを示します。

(継承元 ConfigurationSection)
IsReadOnly()

ConfigurationElement オブジェクトが読み取り専用かどうかを示す値を取得します。

(継承元 ConfigurationElement)
ListErrors(IList)

この ConfigurationElement オブジェクトおよびすべてのサブ要素の無効なプロパティのエラーを、渡されたリストに追加します。

(継承元 ConfigurationElement)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
OnDeserializeUnrecognizedAttribute(String, String)

逆シリカル化中に不明な属性が発生したかどうかを示す値を取得します。

(継承元 ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

逆シリカル化中に不明な要素が発生したかどうかを示す値を取得します。

(継承元 ConfigurationElement)
OnRequiredPropertyNotFound(String)

必要なプロパティが見つからないと例外がスローされます。

(継承元 ConfigurationElement)
PostDeserialize()

逆シリアル化後に呼び出されます。

(継承元 ConfigurationElement)
PreSerialize(XmlWriter)

シリアル化前に呼び出されます。

(継承元 ConfigurationElement)
Reset(ConfigurationElement)

ConfigurationElement オブジェクトの内部状態 (ロックやプロパティ コレクションなど) をリセットします。

(継承元 ConfigurationElement)
ResetModified()

IsModified() メソッドの値が派生クラスに実装されたときに、false にリセットします。

(継承元 ConfigurationSection)
SerializeElement(XmlWriter, Boolean)

派生クラスに実装されている場合、この構成要素の内容を構成ファイルに書き込みます。

(継承元 ConfigurationElement)
SerializeSection(ConfigurationElement, String, ConfigurationSaveMode)

ファイルに書き込む 1 つのセクションとして、ConfigurationSection オブジェクトのアンマージされたビューを含む XML 文字列を作成します。

(継承元 ConfigurationSection)
SerializeToXmlElement(XmlWriter, String)

派生クラスに実装されている場合、この構成要素の外側のタグを構成ファイルに書き込みます。

(継承元 ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

プロパティを指定した値に設定します。

(継承元 ConfigurationElement)
SetReadOnly()

IsReadOnly() オブジェクトおよびすべてのサブ要素に ConfigurationElement プロパティを設定します。

(継承元 ConfigurationElement)
ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName)

指定したターゲット バージョンの.NET Frameworkに対して構成オブジェクト階層をシリアル化するときに、指定した要素をシリアル化する必要があるかどうかを示します。

(継承元 ConfigurationSection)
ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement)

指定したターゲット バージョンの.NET Frameworkの構成オブジェクト階層をシリアル化するときに、指定したプロパティをシリアル化するかどうかを示します。

(継承元 ConfigurationSection)
ShouldSerializeSectionInTargetVersion(FrameworkName)

指定したターゲット バージョンの.NET Frameworkの構成オブジェクト階層をシリアル化するときに、現在ConfigurationSectionのインスタンスをシリアル化する必要があるかどうかを示します。

(継承元 ConfigurationSection)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

保存しないすべての値を削除するには、ConfigurationElement オブジェクトを変更します。

(継承元 ConfigurationElement)

適用対象

こちらもご覧ください