【发布时间】:2018-05-30 13:03:05
【问题描述】:
我在Web.config 中有以下部分:
<httpProtocol>
<customHeaders>
<remove name="X-UA-Compatible" />
<remove name="X-Frame-Options" />
<remove name="X-XSS-Protection" />
<remove name="X-Content-Type-Options" />
<add name="X-UA-Compatible" value="IE=Edge" />
<add name="X-Frame-Options" value="DENY" />
<add name="X-XSS-Protection" value="1; mode=block"></add>
<add name="X-Content-Type-Options" value="nosniff" />
</customHeaders>
</httpProtocol>
我想将<customHeaders> 提取到名为web.customer.customHeaders.config 的配置文件中。为了实现这一点,我在我的Web.config 所在的同一位置创建了web.customer.customHeaders.config 文件,并在其中编写了以下XML:
<customHeaders>
<remove name="X-UA-Compatible" />
<remove name="X-Frame-Options" />
<remove name="X-XSS-Protection" />
<remove name="X-Content-Type-Options" />
<add name="X-UA-Compatible" value="IE=Edge" />
<add name="X-Frame-Options" value="DENY" />
<add name="X-XSS-Protection" value="1; mode=block"></add>
<add name="X-Content-Type-Options" value="nosniff" />
</customHeaders>
我还在我的Web.config 文件中更改了<customHeaders> 部分:
<httpProtocol>
<customHeaders configSource="web.customer.customHeaders.config" />
</httpProtocol>
但不幸的是,configSource 属性无法识别。结果,提取的文件无法读取并插入到我的Web.config 文件中。
我的问题是:如何从 web.config 中提取一个单独的文件中的部分。
如果您有任何线索如何管理,请在下面发表评论。
【问题讨论】:
-
the configSource attribute is not recognised.IDE 是否以某种方式表明了这一点?或者你是在运行时遇到的? -
@mjwills:是的。有一条波浪线,当我将鼠标悬停时,提示“不允许使用 'configSource'。”
-
当你运行它时它会起作用吗?见stackoverflow.com/a/5980776/34092
-
这可能会有所帮助。 stackoverflow.com/questions/2232059/…
-
configSource 文件是否有一个 xml 元素标头,该标头在此 answer 中指示?