管理承認 <authorization>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。

概要

<management> 要素の <authorization> 要素は、既定の承認プロバイダーである "ConfigurationAuthorizationProvider" が、インターネット インフォメーション サービス (IIS) 7.0 で有効の場合に、Web サーバーのリモート管理の承認設定を指定します。

: "ConfigurationAuthorizationProvider" は、IIS の Administration.config ファイルを使用して IIS マネージャーの IIS マネージャー承認設定を保存しますが、その他の承認プロバイダーは、別の保存場所を使用する場合があります。

互換性

  IIS 7.0 IIS 6.0
注意 <management><authorization> は IIS 7.0 で新たに導入された要素です。 なし

セットアップ

IIS 7.0 の既定のインストールには、"管理サービス" 役割サービスは含まれません。この役割サービスをインストールする手順は次のとおりです。

Windows Server 2008

  1. タスク バーで [スタート] をクリックし、[管理ツール] をポイントして [サーバー マネージャー] をクリックします。

  2. [サーバー マネージャー] ウィンドウのツリー表示で、[役割] を展開して [Web サーバー (IIS)] をクリックします。

  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールして [役割サービスの追加] をクリックします。

  4. 役割サービスの追加ウィザードの [役割サービスの選択] ページで、[管理サービス] を選択して、[次へ] をクリックします。

    拡大

  5. [インストール オプションの確認] ページで [インストール] をクリックします。

  6. [結果] ページで [閉じる] をクリックします。

Windows Vista

  1. タスク バーで [スタート] をクリックし、[コントロール パネル] をクリックします。

  2. [コントロール パネル] で、[プログラムと機能][Windows の機能の有効化または無効化] の順にクリックします。

  3. [Internet Information Services][Web 管理ツール] の順に展開します。

  4. [IIS 管理サービス] を選択して、[OK] をクリックします。

    拡大

方法

サイトまたはアプリケーションで IIS マネージャー ユーザーを承認する方法

  1. タスク バーで [スタート] をクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで、IIS マネージャー ユーザーを承認する接続、サイト、アプリケーション、またはディレクトリに移動します。

  3. [ホーム] ウィンドウで [IIS マネージャーのアクセス許可] をダブルクリックします。

    拡大

  4. [IIS マネージャーのアクセス許可] ページで、[操作] ウィンドウの [ユーザーの許可] をクリックします。

    拡大

  5. [ユーザーの許可] ダイアログ ボックスで、[IIS マネージャー] を選択して、[選択] をクリックします。

    拡大

  6. [ユーザー] ダイアログ ボックスで、許可するユーザー アカウントを強調表示し、[OK] をクリックします。

    拡大

  7. [ユーザーの許可] ダイアログ ボックスで、[OK] をクリックします。

    拡大

構成

属性

属性 説明
defaultProvider オプションの string 属性。


IIS マネージャーを使用して Web サーバーにリモートで接続する IIS マネージャー ユーザーおよび Windows ユーザーを承認する既定のプロバイダーを指定します。

既定のプロバイダーを変更する場合、管理サービス (WMSVC) を再起動して変更を有効にする必要があります。IIS マネージャーを開いている場合も、IIS マネージャーを開き直してください。

子要素

要素 説明
authorizationRules オプションの要素。

IIS マネージャーを使用してサイトまたはアプリケーションに接続することを承認する IIS マネージャー ユーザーおよび Windows ユーザーを構成します。
providers オプションの要素。

IIS マネージャーを使用してサイトやアプリケーションにリモートで接続する IIS マネージャー ユーザーおよび Windows ユーザーを承認する承認プロバイダーを構成します。

構成サンプル

次の構成サンプルでは、Contoso という名前の IIS マネージャー ユーザー、Test Group という名前の Windows グループ、および Contoso2 という名前の Windows ユーザーが、IIS マネージャーを使用して Default Web Site に接続できるように承認する方法を示します。

<authorizationRules>
   <scope path="/Default Web Site">
      <add name="Contoso" />
      <add name="COMPUTER01\Test Group" isRole="true" />
      <add name="COMPUTER01\Contoso2" />
   </scope>

</authorizationRules>

次の <authorization> 要素の下の既定の <providers> 要素は、"管理サービス" 役割サービスをインストールすると、IIS 7.0 のルート Administration.config ファイルに構成されます。

<authorization defaultProvider="ConfigurationAuthorizationProvider">
   <providers>
      <add name="ConfigurationAuthorizationProvider"
         type="Microsoft.Web.Management.Server.ConfigurationAuthorizationProvider, Microsoft.Web.Management, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

   </providers>
</authorization>

サンプル コード

次のコード サンプルでは、<scope> 要素が、Default Web Site の <authorizationRules> 要素に既に追加されているかどうかを確認します。まだの場合は、<scope> 要素が <authorizationRules> 要素に追加されます。次に、<add> 要素が、ContosoUser という名前のユーザー アカウントを承認する <scope> 要素に追加されます。

AppCmd.exe

: AppCmd.exe を使用して <system.webServer/management/authorization> 設定を構成することはできません。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetAdministrationConfiguration();
         ConfigurationSection authorizationSection = config.GetSection("system.webServer/management/authorization");
         ConfigurationElementCollection authorizationRulesCollection = authorizationSection.GetCollection("authorizationRules");

         ConfigurationElement scopeElement = FindElement(authorizationRulesCollection, "scope", "path", @"/Default Web Site");
         if (scopeElement == null)
         {
            scopeElement = authorizationRulesCollection.CreateElement("scope");
            scopeElement["path"] = @"/Default Web Site";
            authorizationRulesCollection.Add(scopeElement);
         }

         ConfigurationElementCollection scopeCollection = scopeElement.GetCollection();
         ConfigurationElement addElement = scopeCollection.CreateElement("add");
         addElement["name"] = @"ContosoUser";
         scopeCollection.Add(addElement);

         serverManager.CommitChanges();
      }
   }

   private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
   {
      foreach (ConfigurationElement element in collection)
      {
         if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
         {
            bool matches = true;
            for (int i = 0; i < keyValues.Length; i += 2)
            {
               object o = element.GetAttributeValue(keyValues[i]);
               string value = null;
               if (o != null)
               {
                  value = o.ToString();
               }
               if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
               {
                  matches = false;
                  break;
               }
            }
            if (matches)
            {
               return element;
            }
         }
      }
      return null;
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample
   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetAdministrationConfiguration
      Dim authorizationSection As ConfigurationSection = config.GetSection("system.webServer/management/authorization")
      Dim authorizationRulesCollection As ConfigurationElementCollection = authorizationSection.GetCollection("authorizationRules")

      Dim scopeElement As ConfigurationElement = FindElement(authorizationRulesCollection, "scope", "path", "/Default Web Site")
      If (scopeElement Is Nothing) Then
         scopeElement = authorizationRulesCollection.CreateElement("scope")
         scopeElement("path") = "/Default Web Site"
         authorizationRulesCollection.Add(scopeElement)
      End If

      Dim scopeCollection As ConfigurationElementCollection = scopeElement.GetCollection
      Dim addElement As ConfigurationElement = scopeCollection.CreateElement("add")
      addElement("name") = "ContosoUser"
      scopeCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub

   Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
      For Each element As ConfigurationElement In collection
         If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
            Dim matches As Boolean = True
            Dim i As Integer
            For i = 0 To keyValues.Length - 1 Step 2
               Dim o As Object = element.GetAttributeValue(keyValues(i))
               Dim value As String = Nothing
               If (Not (o) Is Nothing) Then
                  value = o.ToString
               End If
               If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
                  matches = False
                  Exit For
               End If
            Next
            If matches Then
               Return element
            End If
         End If
      Next
      Return Nothing
   End Function

End Module

JavaScript

var adminManager = new ActiveXObject("Microsoft.ApplicationHost.WritableAdminManager"); 
adminManager.CommitPath = "MACHINE/WEBROOT"; 
adminManager.SetMetadata("pathMapper", "AdministrationConfig");

var authorizationSection = adminManager.GetAdminSection("system.webServer/management/authorization", "MACHINE/WEBROOT"); 
var authorizationRulesCollection = authorizationSection.ChildElements.Item("authorizationRules").Collection;

var scopeElementPos = FindElement(authorizationRulesCollection, "scope", ["path", "/Default Web Site"]);
if (scopeElementPos == -1)
{
   var scopeElement = authorizationRulesCollection.CreateNewElement("scope");
   scopeElement.Properties.Item("path").Value = "/Default Web Site";
   authorizationRulesCollection.AddElement(scopeElement);
}
else
{
   var scopeElement = authorizationRulesCollection.Item(scopeElementPos);
}

var scopeCollection = scopeElement.Collection;
var addElement = scopeCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "ContosoUser";
scopeCollection.AddElement(addElement);

adminManager.CommitChanges();

function FindElement(collection, elementTagName, valuesToMatch) {
   for (var i = 0; i < collection.Count; i++) {
      var element = collection.Item(i);
      if (element.Name == elementTagName) {
         var matches = true;
         for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
            var property = element.GetPropertyByName(valuesToMatch[iVal]);
            var value = property.Value;
            if (value != null) {
               value = value.toString();
            }
            if (value != valuesToMatch[iVal + 1]) {
               matches = false;
               break;
            }
         }
         if (matches) {
            return i;
         }
      }
   }
   return -1;
}

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT"
adminManager.SetMetadata "pathMapper", "AdministrationConfig"

Set authorizationSection = adminManager.GetAdminSection("system.webServer/management/authorization", "MACHINE/WEBROOT")
Set authorizationRulesCollection = authorizationSection.ChildElements.Item("authorizationRules").Collection

scopeElementPos = FindElement(authorizationRulesCollection, "scope", Array("path", "/Default Web Site"))
If scopeElementPos = -1 Then
   Set scopeElement = authorizationRulesCollection.CreateNewElement("scope")
   scopeElement.Properties.Item("path").Value = "/Default Web Site"
   authorizationRulesCollection.AddElement(scopeElement)
Else
   Set scopeElement = authorizationRulesCollection.Item(scopeElementPos)
End If

Set scopeCollection = scopeElement.Collection
Set addElement = scopeCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "ContosoUser"
scopeCollection.AddElement(addElement)

adminManager.CommitChanges()

Function FindElement(collection, elementTagName, valuesToMatch)
   For i = 0 To CInt(collection.Count) - 1
      Set element = collection.Item(i)
      If element.Name = elementTagName Then
         matches = True
         For iVal = 0 To UBound(valuesToMatch) Step 2
            Set Property = element.GetPropertyByName(valuesToMatch(iVal))
            value = property.Value
            If Not value = Null Then
               value = CStr(value)
            End If
            If Not value = valuesToMatch(iVal + 1) Then
               matches = False
               Exit For
            End If
         Next
         If matches Then
            Exit For
         End If
      End If
   Next
   If matches Then
      FindElement = i
   Else
      FindElement = -1
   End If
End Function

: このドキュメントで紹介している例は、.NET グローバル アセンブリ キャッシュ (GAC) に保存されているマネージ コード アセンブリを使用して示しています。これらの例で示すコードを使用して独自のアセンブリを展開するには、事前に GAC からアセンブリ情報を取得する必要があります。それには、次の手順を実行します。

  • Windows エクスプローラーで C:\Windows\assembly パスを開きます (C: は、オペレーティング システム ドライブを示します)。
  • アセンブリを見つけます。
  • アセンブリを右クリックして [プロパティ] をクリックします。
  • [カルチャ] の値をコピーします (例 : Neutral)。
  • [バージョン] の番号をコピーします (例 : 1.0.0.0)。
  • [公開キー トークン] の値をコピーします (例 : f0e1d2c3b4a59687)。
  • [キャンセル] をクリックします。

次のコード例では、ContosoAuthorizationProvider という名前の承認プロバイダーを管理承認プロバイダーのコレクションに追加し、既定の承認プロバイダーを ContosoAuthorizationProvider に設定します。

AppCmd.exe

: AppCmd.exe を使用して <system.webServer/Management> 設定を構成することはできません。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetAdministrationConfiguration();

         ConfigurationSection authorizationSection = config.GetSection("system.webServer/management/authorization");
         ConfigurationElementCollection providersCollection = authorizationSection.GetCollection("providers");
         ConfigurationElement addElement = providersCollection.CreateElement("add");
         addElement["name"] = @"ContosoAuthorizationProvider";
         addElement["type"] = @"Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0e1d2c3b4a59687";
         providersCollection.Add(addElement);
         authorizationSection["defaultProvider"] = "ContosoAuthorizationProvider";

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetAdministrationConfiguration

      Dim authorizationSection As ConfigurationSection = config.GetSection("system.webServer/management/authorization")
      Dim providersCollection As ConfigurationElementCollection = authorizationSection.GetCollection("providers")
      Dim addElement As ConfigurationElement = providersCollection.CreateElement("add")
      addElement("name") = "ContosoAuthorizationProvider"
      addElement("type") = "Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0e1d2c3b4a59687"
      providersCollection.Add(addElement)
      authorizationSection("defaultProvider") = "ContosoAuthorizationProvider"

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject("Microsoft.ApplicationHost.WritableAdminManager"); 
adminManager.CommitPath = "MACHINE/WEBROOT"; 
adminManager.SetMetadata("pathMapper", "AdministrationConfig");

var authorizationSection = adminManager.GetAdminSection("system.webServer/management/authorization", "MACHINE/WEBROOT"); 
var providersCollection = authorizationSection.ChildElements.Item("providers").Collection;

var addElement = providersCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "ContosoAuthorizationProvider";
addElement.Properties.Item("type").Value = "Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0e1d2c3b4a59687";
providersCollection.AddElement(addElement);
authorizationSection.Properties.Item("defaultProvider").Value = "ContosoAuthorizationProvider";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT"
adminManager.SetMetadata "pathMapper", "AdministrationConfig"

Set authorizationSection = adminManager.GetAdminSection("system.webServer/management/authorization", "MACHINE/WEBROOT")
Set providersCollection = authorizationSection.ChildElements.Item("providers").Collection

Set addElement = providersCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "ContosoAuthorizationProvider"
addElement.Properties.Item("type").Value = "Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0e1d2c3b4a59687"
providersCollection.AddElement(addElement)
authorizationSection.Properties.Item("defaultProvider").Value = "ContosoAuthorizationProvider"

adminManager.CommitChanges()