SOLVED
Home

Manage IIS Settings via ApplicationHost.Config vs. Web.Config

%3CLINGO-SUB%20id%3D%22lingo-sub-824771%22%20slang%3D%22en-US%22%3EManage%20IIS%20Settings%20via%20ApplicationHost.Config%20vs.%20Web.Config%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-824771%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20an%20IIS%20setup%20where%20multiple%20websites%20exist%20that%20all%20share%20the%20same%20document%20root.%20Each%20of%20the%20websites%20have%20a%20specific%20default%20document%20though.%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20has%20been%20managed%20in%20the%20past%20by%20manually%20editing%20the%20applicationHost.config%20file%2C%20adding%20a%20section%20like%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%3CLOCATION%20path%3D%22%26lt%3Ba%20href%3D%22%3Ewww.website3.com%22%26gt%3B%0A%20%20%3CSYSTEM.WEBSERVER%3E%0A%20%20%20%20%3CDEFAULTDOCUMENT%3E%0A%20%20%20%20%20%20%3CFILES%3E%0A%20%20%20%20%20%20%20%20%3CADD%20value%3D%22website3-home.html%22%3E%3C%2FADD%3E%0A%20%20%20%20%20%20%3C%2FFILES%3E%0A%20%20%20%20%3C%2FDEFAULTDOCUMENT%3E%0A%20%20%3C%2FSYSTEM.WEBSERVER%3E%0A%3C%2FLOCATION%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20script%20some%20of%20this%20setup%2C%20and%20I%20am%20trying%20to%20use%20the%20WebAdministration%20powershell%20module%2C%20and%20am%20looking%20at%20AppCmd%2C%20but%20when%20I%20try%20to%20set%20a%20Default%20Document%20setting%20this%20way%2C%20the%20setting%20gets%20added%20to%20Web.Config...%20and%20since%20the%20websites%20have%20a%20shared%20document%20root%2C%20they%20all%20share%20the%20same%20Web.Config%2C%20and%20this%20causes%20a%20problem.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20a%20way%20when%20using%20WebAdministration%20or%20AppCmd%20to%20specify%20that%20I%20want%20the%20change%20made%20specifically%20in%20applicationHost.config%2C%26nbsp%3B%3CEM%3Enot%3C%2FEM%3EWeb.config%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20appreciate%20any%20suggestions!%3C%2FP%3E%3CP%3E~D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-824771%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EManagement%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-824903%22%20slang%3D%22en-US%22%3ERe%3A%20Manage%20IIS%20Settings%20via%20ApplicationHost.Config%20vs.%20Web.Config%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-824903%22%20slang%3D%22en-US%22%3E%3CP%3ELooks%20like%20you%20can%20use%20the%26nbsp%3B%3CSTRONG%3E%3CSPAN%20style%3D%22list-style%3A%20circle%3B%20text-align%3A%20left%3B%20color%3A%20%23000000%3B%20text-transform%3A%20none%3B%20text-indent%3A%200px%3B%20letter-spacing%3A%20normal%3B%20font-family%3A%20Segoe%20UI%2CSegoeUI%2CSegoe%20WP%2CHelvetica%20Neue%2CHelvetica%2CTahoma%2CArial%2Csans-serif%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20text-decoration%3A%20none%3B%20word-spacing%3A%200px%3B%20display%3A%20inline%20!important%3B%20white-space%3A%20normal%3B%20orphans%3A%202%3B%20float%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20background-color%3A%20%23ffffff%3B%22%3E%2FAppHostConfig%3C%2FSPAN%3E%3C%2FSTRONG%3Eswitch%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fiis%2Fextensions%2Fintroduction-to-iis-express%2Fiis-80-express-readme%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fiis%2Fextensions%2Fintroduction-to-iis-express%2Fiis-80-express-readme%3C%2FFONT%3E%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-824955%22%20slang%3D%22en-US%22%3ERe%3A%20Manage%20IIS%20Settings%20via%20ApplicationHost.Config%20vs.%20Web.Config%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-824955%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F51719%22%20target%3D%22_blank%22%3E%40Dave%20Patrick%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20reply%20Dave%3B%3CBR%20%2F%3ESo%2C%20I%20am%20looking%20at%20the%20following%3A%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fprevious-versions%2Fwindows%2Fit-pro%2Fwindows-server-2012-R2-and-2012%2Fjj635852(v%3Dws.11%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fprevious-versions%2Fwindows%2Fit-pro%2Fwindows-server-2012-R2-and-2012%2Fjj635852(v%3Dws.11%3C%2FA%3E)%3CBR%20%2F%3Eand%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fiis%2Fconfiguration%2Fsystem.webserver%2Fdefaultdocument%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fiis%2Fconfiguration%2Fsystem.webserver%2Fdefaultdocument%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20seems%20the%20syntax%20I%20want%20to%20specifically%20write%20the%20config%20to%20applicationHost.config%20is%20%2FCOMMIT%3AAPPHOST%20but%20I%20cant%20seem%20to%20figure%20out%20the%20rest%20of%20the%20syntax...%20keep%20getting%20errors%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EPS%20C%3A%5CWindows%5Csystem32%5Cinetsrv%26gt%3B%20.%5Cappcmd.exe%20set%20config%20%22testsite2%22%20%2Fsection%3AdefaultDocument%20%2Fenabled%3Atrue%20%2F%2Bfiles.%5Bvalue%3D'site2-home.html'%5D%20%2Fcommit%3AAPPHOST%0AERROR%20(%20message%3AMalformed%20collection%20indexer%3B%20format%20is%20%5B%40position%2Cname%3D'value'%2Cname2%3D'value2'%2C...%5D.%20The%20%40position%20specifier%20is%20optional%2C%20and%20be%20'%40start'%2C%20'%40end'%2C%20or%20'%40N'%20where%20N%20is%20a%20numeric%20index%20i%0Anto%20the%20collection.%20)%0APS%20C%3A%5CWindows%5Csystem32%5Cinetsrv%26gt%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-825805%22%20slang%3D%22en-US%22%3ERe%3A%20Manage%20IIS%20Settings%20via%20ApplicationHost.Config%20vs.%20Web.Config%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-825805%22%20slang%3D%22en-US%22%3E%3CP%3EMight%20give%20the%20quotes%20a%20try.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fforums.iis.net%2Ft%2F1164076.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3Ehttps%3A%2F%2Fforums.iis.net%2Ft%2F1164076.aspx%3C%2FFONT%3E%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-827024%22%20slang%3D%22en-US%22%3ERe%3A%20Manage%20IIS%20Settings%20via%20ApplicationHost.Config%20vs.%20Web.Config%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-827024%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F51719%22%20target%3D%22_blank%22%3E%40Dave%20Patrick%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYep%20-%20that%20did%20it...%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EPS%20C%3A%5CWindows%5Csystem32%5Cinetsrv%26gt%3B%20.%5Cappcmd.exe%20set%20config%20%22testsite2%22%20%2Fsection%3AdefaultDocument%20%2Fenabled%3Atrue%20%22%2F%2Bfiles.%5Bvalue%3D'site2-home.html'%5D%22%20%2Fcommit%3AAPPHOST%0AApplied%20configuration%20changes%20to%20section%20%22system.webServer%2FdefaultDocument%22%20for%20%22MACHINE%2FWEBROOT%2FAPPHOST%2Ftestsite2%22%20at%20configuration%20commit%20path%20%22MACHINE%2FWEBROOT%2FAPPHOST%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20much!!%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-827026%22%20slang%3D%22en-US%22%3ERe%3A%20Manage%20IIS%20Settings%20via%20ApplicationHost.Config%20vs.%20Web.Config%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-827026%22%20slang%3D%22en-US%22%3E%3CP%3EGlad%20to%20hear%2C%20you're%20welcome.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E(please%20don't%20forget%20to%20mark%20my%20reply%20as%20best%20response)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
David Levine
Occasional Contributor

I have an IIS setup where multiple websites exist that all share the same document root. Each of the websites have a specific default document though. 

This has been managed in the past by manually editing the applicationHost.config file, adding a section like

<location path="<a href="http://www.website3.com" target="_blank">www.website3.com</a>">
  <system.webServer>
    <defaultDocument>
      <files>
        <add value="website3-home.html" />
      </files>
    </defaultDocument>
  </system.webServer>
</location>

 

I am trying to script some of this setup, and I am trying to use the WebAdministration powershell module, and am looking at AppCmd, but when I try to set a Default Document setting this way, the setting gets added to Web.Config... and since the websites have a shared document root, they all share the same Web.Config, and this causes a problem.

 

Is there a way when using WebAdministration or AppCmd to specify that I want the change made specifically in applicationHost.config, not Web.config?

 

I appreciate any suggestions!

~D

 

5 Replies

@Dave Patrick 

 

Thanks for the reply Dave;
So, I am looking at the following:
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/jj...)
and
https://docs.microsoft.com/en-us/iis/configuration/system.webserver/defaultdocument/

 

It seems the syntax I want to specifically write the config to applicationHost.config is /COMMIT:APPHOST but I cant seem to figure out the rest of the syntax... keep getting errors:

 

PS C:\Windows\system32\inetsrv> .\appcmd.exe set config "testsite2" /section:defaultDocument /enabled:true /+files.[value='site2-home.html'] /commit:APPHOST
ERROR ( message:Malformed collection indexer; format is [@position,name='value',name2='value2',...]. The @position specifier is optional, and be '@start', '@end', or '@N' where N is a numeric index i
nto the collection. )
PS C:\Windows\system32\inetsrv>
Solution

Might give the quotes a try.

https://forums.iis.net/t/1164076.aspx

 

 

 

@Dave Patrick 

Yep - that did it...

PS C:\Windows\system32\inetsrv> .\appcmd.exe set config "testsite2" /section:defaultDocument /enabled:true "/+files.[value='site2-home.html']" /commit:APPHOST
Applied configuration changes to section "system.webServer/defaultDocument" for "MACHINE/WEBROOT/APPHOST/testsite2" at configuration commit path "MACHINE/WEBROOT/APPHOST"

 

Thank you so much!! 

Glad to hear, you're welcome.

 

(please don't forget to mark my reply as best response)

 

 

Related Conversations
Extentions Synchronization
Deleted in Discussions on
3 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
36 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies