基本認証 <basicAuthentication>

概要

<basicAuthentication> 要素には、インターネット インフォメーション サービス (IIS) 7 基本認証モジュールの構成設定が含まれています。 この要素を構成して、基本認証を有効または無効にし、領域と既定のログオン ドメインを特定し、モジュールが使用するログオン方法を決定します。

基本認証スキームは、ユーザー名とパスワードの情報を収集する業界標準の方法として広く利用されています。 基本認証では、暗号化されていない形式でユーザー名とパスワードがネットワーク経由で送信されます。 SSL 暗号化を基本認証と組み合わせて使用すると、インターネットまたは企業ネットワーク経由で送信されるユーザー アカウント情報をセキュリティで保護できます。

互換性

バージョン メモ
IIS 10.0 <basicAuthentication> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <basicAuthentication> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <basicAuthentication> 要素は IIS 8.0 では変更されませんでした。
IIS 7.5 <basicAuthentication> 要素は、IIS 7.5 では変更されませんでした。
IIS 7.0 <basicAuthentication> 要素が IIS 7.0 で導入されました。
IIS 6.0 <basicAuthentication> 要素は、IIS 6.0 AuthType および AuthFlags メタベース プロパティの一部を置き換えます。

段取り

IIS 7 以降の既定のインストールには、基本認証の役割サービスは含まれません。 インターネット インフォメーション サービス (IIS) で基本認証を使用するには、役割サービスをインストールし、Web サイトまたはアプリケーションの匿名認証を無効にしてから、サイトまたはアプリケーションの基本認証を有効にする必要があります。

基本認証の役割サービスをインストールするには、次の手順を使用します。

Windows Server 2012 または Windows Server 2012 R2

  1. タスク バーで [サーバー マネージャー]をクリックします。
  2. [サーバー マネージャー] で、[管理] メニューをクリックし、[役割と機能の追加] をクリックします。
  3. 役割と機能の追加ウィザードで、[次へ] をクリックします。 [インストールの種類] を選択し、[次へ] をクリックします。 対象サーバーを選択し、[次へ] をクリックします。
  4. [サーバーの役割] ページで [Web サーバー (IIS)] を展開し、[Web サーバー][セキュリティ][基本認証] の順に展開します。 次へ をクリックします。
    Screenshot of Basic Authentication selected in a Windows Server 2012 interface.
  5. [機能の選択] ページで、[次へ] をクリックします。
  6. [インストール オプションの確認] ページで、[インストール] をクリックします。
  7. [結果] ページで、 [閉じる]をクリックします。

Windows 8 または Windows 8.1

  1. [スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] をクリックします。
  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。
  3. [インターネット インフォメーション サービス] を展開し、[World Wide Web Services] を展開し、[セキュリティ] を展開して、[基本認証] を選択します。
    Screenshot of Basic Authentication selected in a Windows 8 interface.
  4. OK をクリックします。
  5. 閉じるをクリックします。

Windows Server 2008 または Windows Server 2008 R2

  1. タスク バーで [スタート] をクリックし、[管理ツール] をポイントして、[サーバー マネージャー] をクリックします。
  2. [Server Manager] (サーバー マネージャー) 階層ウィンドウで [ロール] を展開し、[Web Server (IIS)] (Web サーバー (IIS)) をクリックします。
  3. [Web Server (IIS)] (Web サーバー (IIS)) ウィンドウで、[Role Services] (役割サービス) セクションまでスクロールし、[Add Role Services] (役割サービスの追加) をクリックします。
  4. 役割サービスの追加ウィザード[役割サービスの選択] ページで、[基本認証] を選択し、[次へ] をクリックします。 Screenshot of Basic Authentication selected in a Windows Server 2008 interface.
  5. [インストール オプションの確認] ページで、[インストール] をクリックします。
  6. [結果] ページで、 [閉じる]をクリックします。

Windows Vista または Windows 7

  1. タスク バーで、[スタート][コントロール パネル] の順にクリックします。
  2. [コントロール パネル][プログラムと機能] をクリックし、[Turn Windows Features on or off] (Windows の機能の有効化または無効化) をクリックします。
  3. [インターネット インフォメーション サービス] を展開し、[World Wide Web Services][セキュリティ][基本認証] の順に展開して [OK] をクリックします。
    Screenshot of Basic Authentication selected in a Windows Vista or Windows 7 interface.

操作方法

基本認証を有効にして、匿名認証を無効にする方法

  1. インターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

      • タスク バーで、[サーバー マネージャー] をクリックし、[ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows 8 または Windows 8.1 を使用している場合:

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
      • [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

      • タスク バーで、[スタート] ボタンをクリックし、[管理ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows Vista または Windows 7 を使用している場合:

      • タスク バーで、[スタート][コントロール パネル] の順にクリックします。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウで、サーバー名を展開し、[サイト] を展開し、基本認証を有効にするサイト、アプリケーション、または Web サービスをクリックします。

  3. [ホーム] ウィンドウの [セキュリティ] セクションまでスクロールし、[認証] をダブルクリックします。

  4. [認証] ウィンドウで [基本認証] を選択し、[操作] ウィンドウで [有効] をクリックします。

  5. [認証] ウィンドウで [匿名認証] を選択し、[操作] ウィンドウで [無効] をクリックします。
    Screenshot of Anonymous Authentication selected in the Authentication pane.

構成

<basicAuthentication> 要素は、サイト、アプリケーション、仮想ディレクトリ、URL レベルで構成できます。 役割サービスをインストールすると、IIS 7 は ApplicationHost.config ファイルに次の構成設定をコミットします。

<basicAuthentication enabled='false' />

属性

属性 説明
defaultLogonDomain 省略可能で、 String 型の属性。

基本認証の既定のログオン ドメインを指定します。
enabled 省略可能な Boolean 属性です。

基本認証が有効かどうかを指定します。

既定値は false です。
logonMethod 省略可能な列挙型属性。

logonMethod 属性には、次のいずれかの値を指定できます。 既定値は、ClearText です。
Value 説明
Batch このログオンの種類は、ユーザーが直接介入することなく、そのユーザーの代わりにプロセスが実行される、バッチ サーバーを対象としています。

数値は 1 です。
ClearText このログオンの種類では、名前とパスワードを認証パッケージに保持します。これにより、サーバーはクライアントを偽装しつつ他のネットワーク サーバーに接続できます。

数値は 3 です。
Interactive このログオンの種類は、コンピューターを対話的に使用するユーザーを対象としています。

数値は 0 です。
Network このログオンの種類は、プレーンテキスト パスワードを認証するハイ パフォーマンス サーバー向けです。 このログオンの種類の資格情報はキャッシュされません。

数値は 2 です。
realm 省略可能で、 String 型の属性。

基本認証の領域を指定します。

子要素

なし。

構成サンプル

次の構成サンプルでは、Web サイト、Web アプリケーション、または Web サービスの基本認証を有効にします。 既定では、これらの設定は ApplicationHost.config ファイルに含める必要があります。また、これらの設定を <location> 要素に含め、path 属性を使用して、認証設定を適用する Web サイトまたはアプリケーションを定義する必要があります。

<security>
   <authentication>
      <anonymousAuthentication enabled="false" />
      <basicAuthentication enabled="true" />
   </authentication>
</security>

サンプル コード

次の例では、サイトの基本認証を有効にします。

AppCmd.exe

appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/basicAuthentication /enabled:"True" /commit:apphost

Note

AppCmd.exe を使用してこれらの設定を構成する場合は、commit パラメーターを必ず apphost に設定する必要があります。 これにより、ApplicationHost.config ファイルの適切な場所セクションに構成設定がコミットされます。

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.GetApplicationHostConfiguration();

            ConfigurationSection basicAuthenticationSection = config.GetSection("system.webServer/security/authentication/basicAuthentication", "Contoso");
            basicAuthenticationSection["enabled"] = true;

            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.GetApplicationHostConfiguration

        Dim basicAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/basicAuthentication", "Contoso")
        basicAuthenticationSection("enabled") = True

        serverManager.CommitChanges()
    End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var basicAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/basicAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
basicAuthenticationSection.Properties.Item("enabled").Value = true;

adminManager.CommitChanges();

VBScript

Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set basicAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/basicAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
basicAuthenticationSection.Properties.Item("enabled").Value = True

adminManager.CommitChanges()