阻止 IIS 中的目录访问但允许特定文件通过

chr*_*isd 3 iis web.config

是否可以通过 IIS 中的 web.config 阻止对目录的访问(不包括一小组 IP),但允许每个人通过一个特定文件。

我问的原因是,我想阻止 WordPress 中的 wp-admin 目录,但 admin-ajax.php 确实需要可以从外部访问。

谢谢。

chr*_*isd 5

为了将来参考,这是解决方案:

<location path="wp-admin">
    <system.webServer>
        <security>
            <ipSecurity allowUnlisted="false">
    <clear/> 
                <add ipAddress="ipaddr" allowed="true" />
            </ipSecurity>
        </security>
    </system.webServer>
</location>

<location path="wp-admin/admin-ajax.php">
    <system.webServer>
        <security>
            <ipSecurity allowUnlisted="true">
            </ipSecurity>
        </security>
    </system.webServer>
</location>
Run Code Online (Sandbox Code Playgroud)