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

你说的曾经没有我的故事 提交于 2019-11-29 23:22:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!