ASP.Net 如何通过web.config 文件(.htaccess 类似)限制对特定IP 地址的访问到特定页面?

ASP.Net How to limit access to a particular IP address to a particular page through web.config file (.htaccess similar)?

我正在处理的项目包含 "Views" 文件夹下的三个文件夹:Home、Shared 和 Data 文件夹。

我可以在我的 web.config 文件中添加什么来拒绝除 IP 地址为 xxx.x.xx.xx 的人之外的所有人访问?

本质上,将 .htaccess 文件放入 views 下的 "Data" 文件夹中的等效代码为:

order deny,allow
deny from all
allow from xxx.x.xx.xx

有没有办法在没有活动目录的情况下做到这一点?

在 IIS7 上使用 IPSecurity 通过 IP 地址进行限制:

<system.webServer>
  <security>
    <ipSecurity allowUnlisted="false">          
       <clear/>
       <add ipAddress="xxx.x.xx.xx" allowed="true"/>  
    </ipSecurity>
  </security>

https://www.iis.net/configreference/system.webserver/security/ipsecurity

类似主题:Best way to restrict access by IP address?, Internal Server Error with web.config ipSecurity, http://www.victor-ratajczyk.com/post/2011/12/21/Webconfig-ipSecurity-Allow-specific-IP-addresses-Deny-all-others.aspx