我有一个在 Azure 上运行的 Episerver 网站,出于安全原因,我想使用 IP 地址白名单来阻止对 cms 管理部分的任何请求的访问。
我过去曾对在 Windows 服务器上运行的网站执行过此操作,但我从未在 Azure 托管网站上执行过此操作。我已经尝试过在以前的网站上采取的方法,在 web.config 中为我试图限制的位置添加一个安全部分,例如:
<location path="cms/admin">
<system.webServer>
</ipSecurity>
<add allowed="true" ipAddress="{my ip address}" subnetMask="255.255.255.255" />
...
</security>
</system.webServer>
</location>
这在本地工作,但当我将 web.config 部署到 Azure 时,它不起作用。它阻止任何用户(包括白名单中的用户)访问该位置。
我还考虑过使用应用程序->网络->访问限制在portal.azure中进行更改,但这看起来是为了控制对整个应用程序的访问,这不是我想要的。
有谁知道我这样做是否不正确,特别是对于 Azure 网站?我错过了访问限制中的设置吗?
谢谢
山姆
最佳答案
您可以使用iis url重写规则来阻止请求以限制特定路径的ip:
<rule name="RequestBlockingRule1" patternSyntax="Wildcard" stopProcessing="true">
<match url="cms/admin" />
<conditions>
<add input="{REMOTE_ADDR}" pattern="192.168.2.*" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
</rule>
如果您想允许某些 IP,则可以添加另一个与模式不匹配的条件。
更多详细信息您可以引用以下文章:
关于asp.net - 如何限制对 Azure 上运行的网站部分的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57145534/