Freigeben über


IIS 7/7.5 .net configuration settings using appcmd.exe and IIS Manager

Just recently I came across an issue where customer was using appcmd.exe to make changes to the Application Settings and Configuration Settings he had made using IIS Manager. I am using Application Settings for this post but it holds true for all the ASP.NET settings from IIS Manager.

Application Settings using IIS Manager first at the Server Level, in our example it’s Sample

image1

the setting gets reflected in web.config file in C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG folder.

image2

Now, creating the new application settings on the Default Web Site, in our example it’s Sample2.

image3

An entry is created in the web.config file at the website’s home directory, in our example its C:\inetpub\wwwroot folder.

image4

If you create a new Application Settings at a virdir level, a new web.config will be created with the entry.

Now, the customer was following the article IIS 7.0: Remove an Application Setting and using appcmd.exe he wanted to remove the first entry i.e. Sample

The command he used as per the article was: appcmd.exe set config /commit:MACHINE /section:appSettings /-“[key=’Sample’,value=’1’]”

Result:

image5

So, what’s going wrong?

Here the command is looking for the appSettings parameter and the key in MACHINE i.e. machine.config but it can not find it and hence the error. We now know the key is created in web.config, so what is the command to make the changes in web.config?

The correct command is: appcmd.exe set config /commit:WEBROOT /section:appSettings /-“[key=’Sample’,value=’1’]”

image6

Check the IIS Manager and the entry is now removed.

Similarly, to remove appSettings from Default Web Site, the command is: appcmd.exe set config “Default Web Site” /section:appSettings /-“[key=’Sample2’,value=’2’]”

image7

And to remove appSettings from NewVirDir i.e. the virtual directory under Default Web Site, the command is: appcmd.exe set config “Default Web Site/NewVirDir” /section:appSettings /-“[key=’Sample3’,value=’3’]”

image8

Now, let’s create appSettings using appcmd.exe using the different variant’s and see where they get reflected

image9

Machine.config in C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG

image10

Web.config in C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG

image11

applicationHost.config in C:\Windows\System32\inetsrv\config, since applicationHost.config is the global configuration file for IIS

image12

applicationHost.config in C:\Windows\System32\inetsrv\config. The above command does not make much sense as it is not specific to Default Web Site and since it’s reflected in applicationHost.config it will apply for all web sites/virdir on the server which inherits the setting.

image13

web.config in C:\inetpub\wwwroot folder

HTH.