Home > OS >  appcmd cannot add duplicate collection entry of type 'add' with unique key attribute '
appcmd cannot add duplicate collection entry of type 'add' with unique key attribute '

Time:10-06

Trying to allow specific file types in IIS via the appcmd. Using this code:

appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering / "fileExtensions.[fileExtension='.txt',allowed='True']"

If the file extension is already listed in IIS to be either allowed or denied I get this error:

cannot add duplicate collection entry of type 'add' with unique key attribute 'file extension' set to '.txt'

I think I need to remove the specific file extension allow/deny rules in IIS before adding them back, but I don't know how to do that via appcmd.

CodePudding user response:

Change the " " in front of fileExtensions to "-" to remove config

appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /-"fileExtensions.[fileExtension='.txt',allowed='True']"   

CodePudding user response:

Use this to add specific file types:

appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering / "fileExtensions.[fileExtension='.txt']" 

Use this to remove specific file types:

appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /-"fileExtensions.[fileExtension='.txt']"
  • Related