首页 > 解决方案 > appcmd 无法添加类型为“add”且唯一键属性“文件扩展名”设置为“.txt”的重复集合条目

问题描述

试图通过 appcmd 允许 IIS 中的特定文件类型。使用此代码:

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

如果文件扩展名已在 IIS 中列出允许或拒绝,我会收到此错误:

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

我想我需要先删除 IIS 中的特定文件扩展名允许/拒绝规则,然后再将它们添加回来,但我不知道如何通过 appcmd 执行此操作。

标签: asp.net-mvcbatch-fileiiscmd

解决方案


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']"

推荐阅读