仮想ディレクトリの既定値 <virtualDirectoryDefaults>

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

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

概要

<application> 要素の <virtualDirectoryDefaults> 要素では、親アプリケーション内のすべての仮想ディレクトリの既定の設定を指定します。<virtualDirectoryDefaults> 要素は、親アプリケーション内のすべての仮想ディレクトリにおいて、明示的に属性を定義していない場合に、暗黙的に共有する共通の属性を定義するのに役立ちます。

: 特定の仮想ディレクトリにおいて <virtualDirectoryDefaults> セクションと <virtualDirectory> セクションの両方で同じ属性または子要素が構成されている場合、その仮想ディレクトリでは <virtualDirectory> セクションの構成が使用されます。

互換性

  IIS 7.0 IIS 6.0
説明 <application><virtualDirectoryDefaults> は IIS 7.0 で新たに導入された要素です。 なし

セットアップ

<application> 要素の <virtualDirectoryDefaults> 要素は、IIS 7.0 の既定のインストールに含まれています。

方法

アプリケーションの既定の仮想ディレクトリ資格情報を構成する方法

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

  2. [接続] ウィンドウで、対象のサーバー名、[サイト] ノード、対象のサイトのノードの順に展開し、対象のアプリケーション名をクリックします。

  3. サイトの [ホーム] ウィンドウで、[操作] ウィンドウにある [仮想ディレクトリの表示] をクリックします。

    拡大

  4. [仮想ディレクトリ] ウィンドウで、[操作] ウィンドウにある [仮想ディレクトリの既定値の設定] をクリックします。

    拡大

  5. [仮想ディレクトリの既定値] ダイアログ ボックスで、アプリケーションの既定の仮想ディレクトリ資格情報を指定して [OK] をクリックします。

    拡大

構成

属性

属性 説明
allowSubDirConfig オプションの Boolean 属性。

True の場合は、IIS は現在の階層より下のコンテンツ ディレクトリで Web.config ファイルを検索し、False の場合は、現在の階層より下のコンテンツ ディレクトリで Web.config ファイルを検索しません。

既定値は true です。
logonMethod オプションの enum 属性。

親サイト内のアプリケーションのすべての仮想ディレクトリでの既定のログオン方法を指定します。

logonMethod 属性には、次のいずれかの値を指定できます既定値は ClearText です。

---------------------------------------------------------------------------------------------------------

値: Batch

説明:

  • このログオンの種類は、ユーザーの直接的な介入なしに、ユーザーの代理としてプロセスを実行するバッチ サーバー用です。
  • 数値は 1 です。

値: ClearText

説明:

  • このログオンの種類では、認証パッケージに名前とパスワードを保存します。それによって、サーバーがクライアントになりすまして、他のネットワーク サーバーに接続できるようになります。
  • 数値は 3 です。

値: Interactive

説明:

  • このログオンの種類は、コンピューターを対話的に使用するユーザー用です。
  • 数値は 0 です。

値: Network

説明:

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

*これらの値の詳細については、MSDN サイトの「LogonUser」(英語) を参照してください。

password オプションの string 属性。

ユーザー名に関連付けられるパスワードを指定します。

: 暗号化されていないパスワード文字列が構成ファイルに保存されないようにするために、必ず AppCmd.exe または IIS マネージャーを使用してパスワードを入力してください。これらの管理ツールを使用すると、パスワード文字列は自動的に暗号化されてから XML 構成ファイルに書き込まれます。そのため、暗号化されていないパスワードを保存するよりも、パスワードのセキュリティが強化されます。
path オプションの string 属性。

親サイトのアプリケーション内のすべての仮想ディレクトリの既定の仮想パスを指定します。
physicalPath オプションの string 属性。

親サイトのアプリケーション内のすべての仮想ディレクトリの既定の物理パスを指定します。
userName オプションの string 属性。

親サイトのアプリケーション内のすべての仮想ディレクトリの構成ファイルとコンテンツにアクセスできる、既定のアカウントのユーザー名を指定します。

子要素

なし。

構成サンプル

次の構成サンプルでは、Default Web Site の "/MyApp" アプリケーションの仮想ディレクトリに対する、既定のログオン方法を指定します。

<sites>
   <site name="Default Web Site" id="1">
      <application path="/">

         <virtualDirectory path="/" physicalPath="C:\Inetpub\wwwroot" />
      </application>
      <application path="/MyApp" applicationPool="DefaultAppPool">
         <virtualDirectory path="/" physicalPath="C:\inetpub\myapp" />
         <virtualDirectoryDefaults logonMethod="Network" />
      </application>

      <bindings>
         <binding protocol="http" bindingInformation="*:80:" />
      </bindings>
  </site>
</sites>

サンプル コード

次のコード サンプルでは、Default Web Site の "/MyApp" アプリケーションの仮想ディレクトリに対する、既定のログオン方法を指定します。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].[path='/MyApp'].virtualDirectoryDefaults.logonMethod:Network" /commit:apphost

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 sitesSection = config.GetSection("system.applicationHost/sites");

         ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
         ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"Default Web Site");
         if (siteElement == null) throw new InvalidOperationException("Element not found!");

         ConfigurationElementCollection siteCollection = siteElement.GetCollection();
         ConfigurationElement applicationElement = FindElement(siteCollection, "application", "path", @"/MyApp");
         if (applicationElement == null) throw new InvalidOperationException("Element not found!");

         ConfigurationElement virtualDirectoryDefaultsElement = applicationElement.GetChildElement("virtualDirectoryDefaults");
         virtualDirectoryDefaultsElement["logonMethod"] = @"Network";

         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.GetApplicationHostConfiguration
      Dim sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")

      Dim sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection
      Dim siteElement As ConfigurationElement = FindElement(sitesCollection, "site", "name", "Default Web Site")
      If (siteElement Is Nothing) Then
         Throw New InvalidOperationException("Element not found!")
      End If

      Dim siteCollection As ConfigurationElementCollection = siteElement.GetCollection
      Dim applicationElement As ConfigurationElement = FindElement(siteCollection, "application", "path", "/MyApp")
      If (applicationElement Is Nothing) Then
         Throw New InvalidOperationException("Element not found!")
      End If

      Dim virtualDirectoryDefaultsElement As ConfigurationElement = applicationElement.GetChildElement("virtualDirectoryDefaults")
      virtualDirectoryDefaultsElement("logonMethod") = "Network"

      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/APPHOST";
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");

var sitesCollection = sitesSection.Collection;
var siteElementPos = FindElement(sitesCollection, "site", ["name", "Default Web Site"]);
if (siteElementPos == -1) throw "Element not found!";
var siteElement = sitesCollection.Item(siteElementPos);

var siteCollection = siteElement.Collection;
var applicationElementPos = FindElement(siteCollection, "application", ["path", "/MyApp"]);
if (applicationElementPos == -1) throw "Element not found!";
var applicationElement = siteCollection.Item(applicationElementPos);

var virtualDirectoryDefaultsElement = applicationElement.ChildElements.Item("virtualDirectoryDefaults");
virtualDirectoryDefaultsElement.Properties.Item("logonMethod").Value = "Network";

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/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")

Set sitesCollection = sitesSection.Collection
siteElementPos = FindElement(sitesCollection, "site", Array("name", "Default Web Site"))
If (siteElementPos = -1) Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If
Set siteElement = sitesCollection.Item(siteElementPos)

Set siteCollection = siteElement.Collection
applicationElementPos = FindElement(siteCollection, "application", Array("path", "/MyApp"))
If (applicationElementPos = -1) Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If
Set applicationElement = siteCollection.Item(applicationElementPos)

Set virtualDirectoryDefaultsElement = applicationElement.ChildElements.Item("virtualDirectoryDefaults")
virtualDirectoryDefaultsElement.Properties.Item("logonMethod").Value = "Network"

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