asp.net - 如何限制对 Azure 上运行的网站部分的访问

标签 asp.net azure iis episerver

我有一个在 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,则可以添加另一个与模式不匹配的条件。

更多详细信息您可以引用以下文章:

Creating Rewrite Rules

Request Blocking - rule

关于asp.net - 如何限制对 Azure 上运行的网站部分的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57145534/

相关文章:

ASP.NET Core 使用 JWT 登录

asp.net - SQL排序,分页,过滤ASP.NET中的最佳实践

asp.net - 多个 bool 的单选按钮

asp.net - url 保存到字符串中无法正确保存 (vb.net)

子网之间的 Azure postgres 数据库专用连接

iis - 有没有办法将 IIS 7.5 重置为出厂设置?

visual-studio-2010 - 如何使 IIS Express 成为 Visual Studio 中的默认 Web 服务器?

php - IIS:如何使用自定义 .ini 文件覆盖某些 php.ini 设置?

javascript - Response.Redirect(Request.RawUrl) 之后的 Response.Write

Azure SQL Server 位置列表受到限制