Virtual Directory <virtualDirectory>

개요

요소는 <virtualDirectory> 요소의 <application> 자식이며 특정 가상 디렉터리에 대한 구성 설정을 제어합니다. 가상 디렉터리 는 IIS(인터넷 정보 서비스) 7에서 지정하고 로컬 또는 원격 서버의 물리적 디렉터리에 매핑하는 디렉터리 이름(경로라고도 함)입니다. 가상 디렉터리 이름은 애플리케이션 URL의 일부가 되며 사용자는 웹 페이지 또는 추가 디렉터리 및 파일 목록과 같은 실제 디렉터리의 콘텐츠에 액세스하기 위해 브라우저에서 URL을 요청할 수 있습니다. 가상 디렉터리의 실제 디렉터리 이름과 다른 이름을 지정하는 경우 URL이 사이트의 루트에 직접 매핑되지 않으므로 사용자가 서버에서 실제 실제 파일 구조를 검색하기가 더 어렵습니다.

IIS 7에서 각 애플리케이션에는 루트 가상 디렉터리라고 하는 가상 디렉터리가 있어야 하며 애플리케이션의 콘텐츠가 포함된 실제 디렉터리에 애플리케이션을 매핑합니다. 그러나 애플리케이션에는 둘 이상의 가상 디렉터리가 있을 수 있습니다. 예를 들어 애플리케이션이 파일 시스템의 다른 위치에서 이미지를 포함하도록 하려는 경우 가상 디렉터리를 사용할 수 있지만, 이미지 파일을 애플리케이션의 루트 가상 디렉터리에 매핑된 실제 디렉터리로 이동하지 않으려는 경우가 있습니다.

호환성

버전 참고
IIS 10.0 <virtualDirectory> 요소가 IIS 10.0에서 수정되지 않았습니다.
IIS 8.5 <virtualDirectory> 요소가 IIS 8.5에서 수정되지 않았습니다.
IIS 8.0 <virtualDirectory> 요소가 IIS 8.0에서 수정되지 않았습니다.
IIS 7.5 <virtualDirectory> 요소가 IIS 7.5에서 수정되지 않았습니다.
IIS 7.0 요소는 <virtualDirectory> IIS 7.0에서 도입되었습니다.
IIS 6.0 요소는 <virtualDirectory> IIS 6.0 IIsWebVirtualDirIIsWebDirectory 메타베이스 개체를 대체합니다.

설치 프로그램

요소는 <virtualDirectory> IIS 7의 기본 설치에 포함됩니다.

방법

새 가상 디렉터리를 만드는 방법

  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. 연결 창에서 서버 이름을 확장하고 사이트를 확장하고 가상 디렉터리를 추가할 웹 사이트를 확장한 다음 가상 디렉터리를 추가할 애플리케이션을 클릭합니다.
    내 애플리케이션 홈 창을 보여 주는 스크린샷

  3. 작업 창에서 가상 디렉터리 보기를 클릭한 다음 가상 디렉터리 추가...를 클릭합니다.

  4. 가상 디렉터리 추가 대화 상자에서 최소한 별칭:실제 경로: 텍스트 상자에 정보를 입력하고 확인을 클릭합니다.
    가상 디렉터리 추가 대화 상자를 보여 주는 스크린샷

    참고

    연결 대상...을 클릭하여 가상 디렉터리의 콘텐츠에 액세스할 때 지정된 자격 증명을 사용하도록 서버를 구성하고 설정 테스트...를 클릭하여 가상 디렉터리에 대한 인증 및 권한 부여 설정을 테스트할 수 있습니다.

구성

요소는 <virtualDirectory> ApplicationHost.config 파일의 서버, 사이트 및 애플리케이션 수준에서 구성할 수 있습니다.

특성

attribute Description
allowSubDirConfig 선택적 부울 특성입니다.

IIS가 현재 수준(true)보다 낮은 콘텐츠 디렉터리에서 Web.config 파일을 찾거나 현재 수준(false)보다 낮은 콘텐츠 디렉터리에서 Web.config 파일을 찾을지 여부를 지정합니다.

기본값은 true입니다.
logonMethod 선택적 열거형 특성입니다.

가상 디렉터리에 대한 로그온 메서드를 지정합니다.

logonMethod 특성은 다음과 같은 가능한 값 중 하나일 수 있습니다. 기본값은 ClearText입니다.
Description
Batch 이 로그온 유형은 사용자의 직접 개입 없이 사용자를 대신하여 프로세스가 실행될 수 있는 일괄 처리 서버를 위한 것입니다.

숫자 값은 입니다 1.
ClearText 이 로그온 형식은 인증 패키지의 이름과 암호를 유지하므로 서버가 클라이언트를 가장하는 동안 다른 네트워크 서버에 연결할 수 있습니다.

숫자 값은 입니다 3.
Interactive 이 로그온 유형은 컴퓨터를 대화형으로 사용하는 사용자를 위한 것입니다.

숫자 값은 입니다 0.
Network 이 로그온 유형은 일반 텍스트 암호를 인증하는 고성능 서버를 위한 것입니다. 이 로그온 유형에 대한 자격 증명은 캐시되지 않습니다.

숫자 값은 입니다 2.
password 선택적 문자열 특성입니다.

사용자 이름과 연결된 암호를 지정합니다.

참고: 암호화되지 않은 암호 문자열을 구성 파일에 저장하지 않도록 하려면 항상 AppCmd.exe 또는 IIS Manager를 사용하여 암호를 입력합니다. 이러한 관리 도구를 사용하는 경우 암호 문자열은 XML 구성 파일에 기록되기 전에 자동으로 암호화됩니다. 이렇게 하면 암호화되지 않은 암호를 저장하는 것보다 더 나은 암호 보안이 제공됩니다.
path 선택적 문자열 특성입니다.

가상 디렉터리의 가상 경로를 지정합니다.
physicalPath 선택적 문자열 특성입니다.

가상 디렉터리의 실제 경로를 지정합니다.
userName 선택적 문자열 특성입니다.

이 가상 디렉터리의 구성 파일 및 콘텐츠에 액세스할 수 있는 계정의 사용자 이름을 지정합니다.

자식 요소

없음

구성 샘플

다음 구성 예제에서는 두 개의 애플리케이션을 <site> 포함하는 요소를 표시합니다. 첫 번째 <application> 요소는 애플리케이션에 대한 루트 가상 디렉터리와 함께 사이트의 루트 애플리케이션을 정의합니다. 두 번째 <application> 요소는 웹 사이트의 CRM 애플리케이션에 대한 구성 설정을 포함합니다. path 특성은 애플리케이션의 경로를 정의합니다. 이 <application> 요소에는 두 <virtualDirectory> 개의 요소가 포함됩니다. 첫 번째는 애플리케이션의 루트 가상 디렉터리를 정의하고, 두 번째는 애플리케이션에 대한 Images 가상 디렉터리를 정의합니다.

<site name="Contoso" id="2" serverAutoStart="true">
   <application path="/">
      <virtualDirectory path="/" physicalPath="C:\Contoso\Content" />
   </application>
   <application path="/CRM">
      <virtualDirectory path="/" physicalPath="C:\Contoso\Content\CRM" />
      <virtualDirectory path="/Images" physicalPath="E:\Images" />
   </application>
   <bindings>
      <binding protocol="http" bindingInformation="*:80:www.contoso.com" />
   </bindings>
</site>

샘플 코드

다음 예제에서는 Contoso라는 사이트에 대해 C:\Inetpub\Contoso\ShoppingCart의 가상 디렉터리 루트를 사용하여 ShoppingCart라는 새 애플리케이션을 만듭니다.

참고

명령 프롬프트 또는 스크립트에서 애플리케이션을 만들 때 애플리케이션에 대한 루트 가상 디렉터리를 명시적으로 만들어야 합니다.

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites /+"[name='Contoso'].[path='/ShoppingCart']" /commit:apphost

appcmd.exe set config -section:system.applicationHost/sites /+"[name='Contoso'].[path='/ShoppingCart'].[path='/',physicalPath='C:\Inetpub\Contoso\ShoppingCart']" /commit:apphost

참고

AppCmd.exe 사용하여 이러한 설정을 구성할 때 커밋 매개 변수 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 sitesSection = config.GetSection("system.applicationHost/sites");
         ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
         ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"Contoso");

         if (siteElement == null) throw new InvalidOperationException("Element not found!");

         ConfigurationElementCollection siteCollection = siteElement.GetCollection();
         ConfigurationElement applicationElement = siteCollection.CreateElement("application");

         applicationElement["path"] = @"/ShoppingCart";
         ConfigurationElementCollection applicationCollection = applicationElement.GetCollection();
         ConfigurationElement virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory");
         virtualDirectoryElement["path"] = @"/";
         virtualDirectoryElement["physicalPath"] = @"C:\Inetpub\Contoso\ShoppingCart";
         applicationCollection.Add(virtualDirectoryElement);
         siteCollection.Add(applicationElement);

         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", "Contoso")

      If (siteElement Is Nothing) Then
         Throw New InvalidOperationException("Element not found!")
      End If

      Dim siteCollection As ConfigurationElementCollection = siteElement.GetCollection
      Dim applicationElement As ConfigurationElement = siteCollection.CreateElement("application")
      applicationElement("path") = "/ShoppingCart"
      Dim applicationCollection As ConfigurationElementCollection = applicationElement.GetCollection
      Dim virtualDirectoryElement As ConfigurationElement = applicationCollection.CreateElement("virtualDirectory")
      virtualDirectoryElement("path") = "/"
      virtualDirectoryElement("physicalPath") = "C:\Inetpub\Contoso\ShoppingCart"
      applicationCollection.Add(virtualDirectoryElement)
      siteCollection.Add(applicationElement)

      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", "Contoso"]);

if (siteElementPos == -1) throw "Element not found!";

var siteElement = sitesCollection.Item(siteElementPos);
var siteCollection = siteElement.Collection;
var applicationElement = siteCollection.CreateNewElement("application");
applicationElement.Properties.Item("path").Value = "/ShoppingCart";
var applicationCollection = applicationElement.Collection;
var virtualDirectoryElement = applicationCollection.CreateNewElement("virtualDirectory");
virtualDirectoryElement.Properties.Item("path").Value = "/";
virtualDirectoryElement.Properties.Item("physicalPath").Value = "C:\\Inetpub\\Contoso\\ShoppingCart";
applicationCollection.AddElement(virtualDirectoryElement);
siteCollection.AddElement(applicationElement);

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 = 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", "Contoso"))

If (siteElementPos = -1) Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If

Set siteElement = sitesCollection.Item(siteElementPos)
Set siteCollection = siteElement.Collection
Set applicationElement = siteCollection.CreateNewElement("application")
applicationElement.Properties.Item("path").Value = "/ShoppingCart"
Set applicationCollection = applicationElement.Collection
Set virtualDirectoryElement = applicationCollection.CreateNewElement("virtualDirectory")
virtualDirectoryElement.Properties.Item("path").Value = "/"
virtualDirectoryElement.Properties.Item("physicalPath").Value = "C:\Inetpub\Contoso\ShoppingCart"
applicationCollection.AddElement(virtualDirectoryElement)
siteCollection.AddElement(applicationElement)

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 IsNull(value) Then
               value = CStr(value)
            End If
            If Not value = CStr(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