08-27-2019 08:27 AM
08-27-2019 08:27 AM
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!
08-27-2019 09:30 AM
Looks like you can use the /AppHostConfig switch
08-27-2019 09:46 AM
Thanks for the reply Dave;
So, I am looking at the following:
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>
08-27-2019 04:39 PM - edited 08-27-2019 07:24 PMSolution
Might give the quotes a try.
08-28-2019 08:14 AM
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!!
08-28-2019 08:16 AM
Glad to hear, you're welcome.
(please don't forget to mark my reply as best response)
by Samer Rustom on May 30, 2020
by ZhangChengwei on May 27, 2020
by Rui Cabral on May 24, 2020
by Jaroslav_Jasek on May 15, 2020
by Vinicius Apolinario on November 07, 2019
by Cosmos Darwin on April 10, 2019
by Jeff Patterson on April 10, 2019