问题
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 ?
回答1:
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 >
回答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
来源:https://stackoverflow.com/questions/26804752/is-it-possible-to-add-security-section-in-web-config-to-external-file