【问题标题】:Is it possible to add security section in web.config to external file是否可以将 web.config 中的安全部分添加到外部文件
【发布时间】:2014-11-07 15:39:09
【问题描述】:

我需要通过配置文件阻止一个巨大的 IP 列表

<security>
      <ipSecurity allowUnlisted="true">
        <clear />          
        <add ipAddress="1.0.1.0" subnetMask="255.255.255.0" />
        <add ipAddress="1.0.2.0" subnetMask="255.255.254.0" />
        <add ipAddress="1.0.8.0" subnetMask="255.255.248.0" />
        <add ipAddress="1.0.32.0" subnetMask="255.255.224.0" />
        ...
      </ipSecurity>
</security>

是否可以将 web.config 中的安全部分添加到外部文件?

【问题讨论】:

  • 是的,你可以,谷歌configSource
  • @tweray 是的,但它不适用于安全部分

标签: asp.net asp.net-mvc web.config-transform


【解决方案1】:

c:\Windows\system32\inetsrv\config\applicationHost.config

更改网络服务器的配置:

来自:

< section name="ipSecurity" overrideModeDefault="Deny" / > 

到:

< section name="ipSecurity" overrideModeDefault="Allow" / > 

和你的 web.config

< configuration > 
< system.webServer > 
< security > 
< ipSecurity configSource="fileWithIps.config" / > 
< /security > 
< /system.webServer > 
< /configuration > 

【讨论】:

    【解决方案2】:

    有多种方法可以实现这一点,但首先我会查看 ConfigurationManager 的 ConfigurationManager.OpenMappedExeConfiguration 映射辅助配置文件的方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-19
      • 1970-01-01
      相关资源
      最近更新 更多