Search code examples
asp.netasp.net-mvcweb.config-transform

Is it possible to add security section in web.config to external file


I need block a huge IP list via config file

<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>

Is it possible to add security section in web.config to external file ?


Solution

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

    change the configuration for the web server:

    from:

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

    to:

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

    and your web.config

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