管理認証資格情報 <credentials>

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

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

概要

<authentication> 要素の <credentials> 要素は、IIS マネージャー ユーザー アカウントの資格情報を指定します。IIS マネージャー ユーザーは、サーバー管理者に承認を受けたサイトおよびアプリケーションに IIS マネージャーを使用して接続することができます。

: <credentials> 要素は、既定の "ConfigurationAuthenticationProvider" を認証プロバイダーとして使用する場合にのみ適用できます。

互換性

  IIS 7.0 IIS 6.0
注意 <authentication><credentials> は 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. [接続] ウィンドウで当該サーバー名をクリックします。

  3. サーバーの [ホーム] ウィンドウで [管理サービス] をダブルクリックします。

    拡大

  4. [管理サービス] ページで [Windows 資格情報または IIS マネージャー資格情報] を選択し、[操作] ウィンドウの [適用] をクリックします。

    拡大

サーバーに IIS マネージャー ユーザー資格情報を追加する方法

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

  2. [接続] ウィンドウで当該サーバー名をクリックします。

  3. サーバーの [ホーム] ウィンドウで [IIS マネージャー ユーザー] をダブルクリックします。

    拡大

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

    拡大

  5. [ユーザーの追加] ダイアログ ボックスで、ユーザー名とパスワードを入力し、[OK] をクリックします。

    拡大

構成

属性

なし。

子要素

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

IIS マネージャー ユーザー アカウントを IIS マネージャー ユーザーのコレクションに追加します。

構成サンプル

次の構成サンプルでは、ContosoUser という名前の IIS マネージャー ユーザーを Administration.config に追加する方法を示します。

<credentials>
   <add name="ContosoUser" password="Encrypted-Password-Data" enabled="true" />
</credentials>

サンプル コード

次のコード サンプルでは、ContosoUser という名前の IIS マネージャー ユーザー アカウントを IIS 7.0 に追加します。

AppCmd.exe

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

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 authenticationSection = config.GetSection("system.webServer/management/authentication");
         ConfigurationElementCollection credentialsCollection = authenticationSection.GetCollection("credentials");
         ConfigurationElement addElement = credentialsCollection.CreateElement("add");
         addElement["name"] = @"ContosoUser";
         addElement["password"] =   GetHashPwssword (@"P@ssw0rd");
         credentialsCollection.Add(addElement);

         serverManager.CommitChanges();
      }
   }
}

public string GetHashPwssword(string passWord)
{            
   SHA256 sha = SHA256.Create();
   byte[] hashBytes = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(passWord));

   byte f1 = 0xf0;
   byte f2 = 0x0f;
   string hexString = "";

   foreach (byte b in hashBytes)
   {
      int first4 = (b & f1) >> 4;
      int second4 = (b & f2);
      hexString = hexString + ((first4 > 9) ? (char)('A' + (first4 - 10)) : (char)('0' + first4));
      hexString = hexString + ((second4 > 9) ? ((char)('A' + (second4 - 10))) : (char)('0' + second4));
   }
   return hexString;   
}

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 authenticationSection As ConfigurationSection = config.GetSection("system.webServer/management/authentication")
      Dim credentialsCollection As ConfigurationElementCollection = authenticationSection.GetCollection("credentials")
      Dim addElement As ConfigurationElement = credentialsCollection.CreateElement("add")
      addElement("name") = "ContosoUser"
      addElement("password") = "P@ssw0rd"
      credentialsCollection.Add(addElement)
      addElement("enabled") = True
      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

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

var authenticationSection = adminManager.GetAdminSection("system.webServer/management/authentication", "MACHINE/WEBROOT"); 
var credentialsCollection = authenticationSection.ChildElements.Item("credentials").Collection;

var addElement = credentialsCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "ContosoUser";
addElement.Properties.Item("password").Value = "P@ssw0rd";
addElement.Properties.Item("enabled").Value = true;
credentialsCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

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

Set authenticationSection = adminManager.GetAdminSection("system.webServer/management/authentication", "MACHINE/WEBROOT")
Set credentialsCollection = authenticationSection.ChildElements.Item("credentials").Collection

Set addElement = credentialsCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "ContosoUser"
addElement.Properties.Item("password").Value = "P@ssw0rd"
addElement.Properties.Item("enabled").Value = True
credentialsCollection.AddElement(addElement)

adminManager.CommitChanges()