본문 바로가기
ASP.NET MVC

ASP.NET MVC] Web.config transform file

by Fastlane 2022. 7. 21.
728x90
반응형

Web.config transform file

deploy시, Web.config 파일이 어떻게 수정되는지 지정하는 XML file이다.

Transformation action은 XML-Document-Transform namespace에서 정의된 XML attribute(xdt prefix, Locator, Transform)를 사용하여 지정한다. 

 

XML attributes 

1) Locator : Web.config element 지정, optional

2) Transform : Locator attribute가 찾은 element로 무엇을 할지 지정

 

Locator Attribute Syntax

1) Condition 

2) Match

3) XPath

 

Transform Attribute Syntax

1) Replace

2) Insert

3) InsertBeform

4) InsertAfter

5) Remove

6) RemoveAll

7) RemoveAttributes

8) SetAttributes

 

Example

Release deploy시, compilation의 debug="true"가 삭제되고, Identity가 계정정보가 있는 것으로 변경되도록 수정해보자. 

Web.config

  <system.web>
    <pages validateRequest="false" />
    <customErrors mode="Off" />
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5" maxRequestLength="20840" requestValidationMode="2.0" />
    <globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" />
	<identity impersonate="false" />
  </system.web>

Web.Release.config

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <!-- <system.web> 노드 아래에는 identity이 하나만 있기 때문에
      "xdt:Locator" 특성을 사용할 필요가 없습니다. -->
	<identity impersonate="true" userName="hello" password="12345" xdt:Transform="Replace"/>
  </system.web>
</configuration>

Web.Release.config Transform이 적용된 Web.config

  <system.web>
    <pages validateRequest="false"/>
    <customErrors mode="Off"/>
    <authentication mode="None"/>
    <compilation targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5" maxRequestLength="20840" requestValidationMode="2.0"/>
    <globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/>
	<identity impersonate="true" userName="hello" password="12345"/>
  </system.web>

Web.Release.config파일 선택 후,
마우스 우측 클릭하여 '변환 미리 보기' 선택하여, 파일 변경을 미리 보기 할 수 있다. 

 

Release 구성으로 게시하면, 변경사항이 적용된 web.config가 생성됨 확인할 수 있다. 

 

728x90
반응형

댓글