연습: Hosted Web Core에 대한 구성 파일 만들기
이 연습에서는 IIS 7에서 사용할 수 있는 Hosted Web Core 기능과 함께 사용할 구성 파일을 만드는 방법을 보여 줍니다.
IIS 7에서 Hosted Web Core 기능을 사용하는 애플리케이션을 만들 때 ApplicationHost.config 파일 형식을 따르는 사용자 지정 구성 파일을 제공해야 합니다. 구성 설정에 따라 애플리케이션은 IIS 7을 사용하는 웹 사이트를 호스팅하는 동일한 서버에서 웹 페이지 및 애플리케이션을 호스트할 수 있습니다. 예를 들어 웹 서버에 TCP 포트 80에서 웹 페이지를 제공하는 웹 사이트가 하나만 있는 경우 TCP 포트 8080에서 웹 페이지를 제공하도록 애플리케이션을 구성할 수 있습니다.
애플리케이션에 사용자 지정 구성 파일이 필요하므로 웹 사이트와 Hosted Web Core 애플리케이션은 동일한 기능 설정을 공유하지 않습니다. 예를 들어 애플리케이션에서 필요하지 않은 동적 기능을 구현하도록 웹 사이트를 구성하거나 웹 사이트에서 사용하지 않는 특정 인증 방법을 요구하도록 애플리케이션을 구성할 수 있습니다.
IIS 7용 ApplicationHost.config 파일에 둘 이상의 애플리케이션 풀이 포함될 수 있지만 IIS 7의 Hosted Web Core 기능은 단일 애플리케이션 풀만 지원합니다.
사전 요구 사항
예제의 단계를 완료하려면 다음 소프트웨어가 필요합니다.
- Windows Vista의 IIS 7.
참고
Windows Vista에서 Hosted Web Core 애플리케이션을 실행해야 하지만 Windows Vista에서 구성 파일을 만들 필요는 없습니다. 다른 버전의 Windows에서 구성 파일을 만든 다음 Windows Vista가 설치된 컴퓨터에 구성 파일을 복사할 수 있습니다.
- Visual Studio 2005.
참고
연습 단계가 동일하지 않을 수도 있지만 Visual Studio .NET 2003 이하를 사용할 수도 있습니다.
구성 파일 만들기
연습의 이 부분의 단계는 정적 콘텐츠를 제공하는 데 필요한 설정이 포함된 Hosted Web Core 애플리케이션에서 사용할 새 구성 파일을 만드는 데 도움이 됩니다.
구성 파일을 만들려면
Visual Studio 2005를 시작합니다.
새 구성 파일을 만듭니다.
파일 메뉴에서 새로 만들기를 가리킨 다음 파일을 클릭합니다.
새 파일 대화 상자가 열립니다.
범주 창에서 일반을 클릭합니다.
템플릿 창에서 XML 파일을 선택합니다.
열기를 클릭합니다.
새 XML 파일이 다음 XML 코드로 열립니다.
<?xml version="1.0" encoding="UTF-8"?>
이 XML 파일을 애플리케이션의 구성 파일로 식별하려면 요소 아래에
<?xml?>
다음 XML 코드를 추가합니다.<configuration> </configuration>
구성 섹션 정의
구성 파일을 만들 때 구성 파일에 포함할 구성 섹션을 정의해야 합니다. 구성 파일에 요소를 추가하여 <configSections>
이 작업을 수행합니다.
configSections 섹션을> 추가<하려면
구성 파일에 포함할 섹션을 정의하는 섹션을 만들려면 요소 내에
<configuration>
다음 XML 코드를 추가합니다.<configSections> </configSections>
섹션에
<system.applicationHost>
포함될 정보를 정의하려면 요소 내에<configSections>
다음 XML 코드를 추가합니다.<sectionGroup name="system.applicationHost" type="System.ApplicationHost.Configuration.SystemApplicationHostSectionGroup"> <section name="applicationPools" type="System.ApplicationHost.Configuration.ApplicationPoolsSection" allowDefinition="MachineOnly" overrideModeDefault="Deny" /> <section name="listenerAdapters" type="System.ApplicationHost.Configuration.ListenerAdaptersSection" allowDefinition="MachineOnly" overrideModeDefault="Deny" /> <section name="log" type="System.ApplicationHost.Configuration.LogSection" allowDefinition="MachineOnly" overrideModeDefault="Deny" /> <section name="sites" type="System.ApplicationHost.Configuration.SitesSection" allowDefinition="MachineOnly" overrideModeDefault="Deny" /> </sectionGroup>
섹션에 포함될 정보를 정의하려면 요소 내에
<configSections>
다음 코드를 추가합니다<system.applicationHost>
.<sectionGroup name="system.webServer" type="System.WebServer.Configuration.SystemWebServerSectionGroup"> <section name="defaultDocument" type="System.WebServer.Configuration.DefaultDocumentSection" overrideModeDefault="Allow" /> <section name="directoryBrowse" type="System.WebServer.Configuration.DirectoryBrowseSection" overrideModeDefault="Allow" /> <section name="globalModules" type="System.WebServer.Configuration.GlobalModulesSection" allowDefinition="MachineOnly" overrideModeDefault="Deny" /> <section name="handlers" type="System.WebServer.Configuration.HandlersSection" overrideModeDefault="Deny" /> <section name="httpLogging" type="System.WebServer.Configuration.HttpLoggingSection" overrideModeDefault="Deny" /> <section name="modules" type="System.WebServer.Configuration.ModulesSection" allowDefinition="MachineToApplication" overrideModeDefault="Deny" /> <sectionGroup name="security" type="System.WebServer.Configuration.SecuritySectionGroup"> <section name="access" type="System.WebServer.Configuration.AccessSection" overrideModeDefault="Deny" /> <sectionGroup name="authentication" type="System.WebServer.Configuration.AuthenticationSectionGroup"> <section name="anonymousAuthentication" type="System.WebServer.Configuration.AnonymousAuthenticationSection" overrideModeDefault="Allow" /> </sectionGroup> </sectionGroup> <section name="staticContent" type="System.WebServer.Configuration.StaticContentSection" overrideModeDefault="Deny" /> </sectionGroup>
<system.applicationHost> 설정 추가
구성 파일에 포함할 섹션을 정의한 경우 구성 섹션을 애플리케이션에 필요한 설정으로 채워야 합니다.
system.applicationHost> 섹션을 <추가하려면
구성 파일에 섹션을
<system.applicationHost>
추가하려면 요소 내에<configuration>
다음 XML 코드를 추가합니다.<system.applicationHost> </system.applicationHost>
애플리케이션 풀을 만들려면 요소 내에
<system.applicationHost>
다음 XML 코드를 추가합니다.<applicationPools> <add name="TestAppPool" /> <applicationPoolDefaults> <processModel identityType="NetworkService" /> </applicationPoolDefaults> </applicationPools>
HTTP용 수신기 어댑터를 정의하려면 요소 내에
<system.applicationHost>
다음 XML 코드를 추가합니다.<listenerAdapters> <add name="http" /> </listenerAdapters>
웹 사이트를 만들려면 요소 내에 다음 XML 코드를 추가합니다
<system.applicationHost>
.<sites> <site name="Test Web Site" id="1"> <application path="/"> <virtualDirectory path="/" physicalPath="D:\inetpub\TestPath\wwwroot" /> </application> <bindings> <binding protocol="HTTP" bindingInformation="*:8080:" /> </bindings> </site> <siteDefaults> <logFile directory="D:\inetpub\TestPath\Logs" /> </siteDefaults> <applicationDefaults applicationPool="TestAppPool" /> <virtualDirectoryDefaults allowSubDirConfig="true" /> </sites>
참고
애플리케이션에 맞게 XML 설정에서 파일 경로 및 서버 바인딩을 변경할 수 있습니다.
<system.webServer> 설정 추가
system.webServer 섹션을 <> 추가하려면
구성 파일에 섹션을
<system.webServer>
추가하려면 요소 내에<configuration>
다음 XML 코드를 추가합니다.<system.webServer> </system.webServer>
애플리케이션에서 사용할 전역 모듈을 정의하려면 요소 내에
<system.webServer>
다음 XML 코드를 추가합니다.<globalModules> <add name="DefaultDocumentModule" image="D:\Windows\system32\inetsrv\defdoc.dll" /> <add name="DirectoryListingModule" image="D:\Windows\system32\inetsrv\dirlist.dll" /> <add name="StaticFileModule" image="D:\Windows\system32\inetsrv\static.dll" /> <add name="AnonymousAuthenticationModule" image="D:\Windows\system32\inetsrv\authanon.dll" /> <add name="HttpLoggingModule" image="D:\Windows\system32\inetsrv\loghttp.dll" /> </globalModules>
애플리케이션에서 사용할 처리기를 정의하려면 요소 내에
<system.webServer>
다음 XML 코드를 추가합니다.<handlers> <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" /> </handlers>
애플리케이션에서 사용할 모듈을 정의하려면 요소 내에
<system.webServer>
다음 XML 코드를 추가합니다.<modules> <add name="DefaultDocumentModule" /> <add name="DirectoryListingModule" /> <add name="StaticFileModule" /> <add name="AnonymousAuthenticationModule" /> <add name="HttpLoggingModule" /> </modules>
디렉터리 검색 및 HTTP 로깅 옵션을 정의하려면 요소 내에
<system.webServer>
다음 XML 코드를 추가합니다.<directoryBrowse enabled="true" /> <httpLogging dontLog="false" />
기본 문서를 사용하도록 설정하려면 요소 내에
<system.webServer>
다음 XML 코드를 추가합니다.<defaultDocument enabled="true"> <files> <add value="default.htm" /> </files> </defaultDocument>
애플리케이션에서 구현할 MIME 형식을 정의하려면 요소 내에
<system.webServer>
다음 XML 코드를 추가합니다.<staticContent> <mimeMap fileExtension=".gif" mimeType="image/gif" /> <mimeMap fileExtension=".htm" mimeType="text/html" /> <mimeMap fileExtension=".jpg" mimeType="image/jpeg" /> <mimeMap fileExtension=".txt" mimeType="text/plain" /> </staticContent>
참고
요소를 더
<mimeMap>
추가하여 MIME 형식을 애플리케이션에 적절하게 추가할 수 있습니다.애플리케이션의 보안 옵션을 정의하려면 요소 내에
<system.webServer>
다음 XML 코드를 추가합니다.<security> <access flags="Read" sslFlags="None" /> <authentication> <anonymousAuthentication enabled="true" userName="IUSR" defaultLogonDomain="" /> </authentication> </security>
이전 단계를 모두 완료한 경우 호스트된 Web Core 애플리케이션에서 액세스할 수 있는 경로에 구성 파일을 저장해야 합니다.
구성 파일의 섹션이 올바르게 정의되지 않은 경우 애플리케이션에 오류가 발생할 수 있습니다. 오류에 따라 서버의 이벤트 뷰어 로그와 애플리케이션에서 자동으로 만든 IIS 로그 파일을 검사하여 문제에 대한 추가 정보를 검색할 수 있습니다. Hosted Web Core 애플리케이션의 문제 해결에 대한 자세한 내용은 연습: 호스트된 웹 코어 애플리케이션 만들기에 나열된 문제 해결 단계를 참조하세요.