管理承認規則 <authorizationRules>

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

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

概要

<authorization> 要素の <authorizationRules> 要素は、既定の承認プロバイダーである "ConfigurationAuthorizationProvider" がインターネット インフォメーション サービス (IIS) 7.0 で有効の場合に、 IIS マネージャーを使用してサイトまたはアプリケーションに接続できるように承認する IIS マネージャー ユーザーおよび Windows ユーザーを指定します。

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

互換性

  IIS 7.0 IIS 6.0
注意 <authorization><authorizationRules> は 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] をクリックします。

    拡大

構成

属性

なし。

子要素

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

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

構成サンプル

次の構成サンプルでは、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>

サンプル コード

次のコード サンプルでは、<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, string keyValues)
   {
      foreach (ConfigurationElement element in collection)
      {
         if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
         {
            if (string.Equals(element.Attributes["path"].Value.ToString(), keyValues, StringComparison.OrdinalIgnoreCase))
            {
               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