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 ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
c:Windowssystem32inetsrvconfigapplicationHost.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 >
Method 2
There are multiple ways you could achieve this, but for a start I would look at the ConfigurationManager’s ConfigurationManager.OpenMappedExeConfiguration method for mapping a secondary config file
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0