How am I able to set the sites web.config "ASPNETCORE_ENVIRONMENT" environmentVariable with APPCMD.exe?
So far I've tried ending it using /commit:MACHINE/WEBROOT
, /commit:webroot
and I get the below:
appcmd.exe set config "Default Web Site/Help" -section:system.webServer/aspNetCore /+"environmentVariables.[name='ASPNETCORE_ENVIRONMENT',value='Standalone']" /commit:MACHINE/WEBROOT
ERROR ( message:Configuration error
Filename: \\?\C:\inetpub\wwwroot\Help\web.config
Line Number: 0
Description: The configuration section 'system.webServer/aspNetCore' cannot be read because it is missing a section declaration
. )
However I can update the "applicationHost.config" using the same code as below but a different /commit
. I don't want to update the "APPHOST" though as I need to do the "web.config", which is where the value already is that I need to update:
set config "Default Web Site/Help" -section:system.webServer/aspNetCore /+"environmentVariables.[name='ASPNETCORE_ENVIRONMENT',value='Standalone']" /commit:apphost
Applied configuration changes to section "system.webServer/aspNetCore" for "MACHINE/WEBROOT/APPHOST/Default Web Site/Help" at configuration commit path "MACHINE/WEBROOT/APPHOST"
Best Answer
I figured this out. First you have to realise the areas that this can be committed to. I found it at https://docs.microsoft.com/en-us/iis/get-started/getting-started-with-iis/getting-started-with-appcmdexe and these are the below which I needed to use the "URL" section:
url — same as default; write configuration at the level for which it is set
site — write configuration in the Web.config at the site root of the url for which it is set
app — write configuration in the Web.config at the app root of the url for which it is set
apphost — write configuration at the server level, in the applicationHost.config file
As our software was was putting a default variable in, I had to first clear it with:
To the add the
ASPNETCORE_ENVIRONMENT