Azure网站上的黑名单特定IP

问题描述 投票:1回答:1

有一些IP地址产生大量异常,可以明确地归类为“可疑行为”。我想阻止这些IP,但别管其他一切。

  • 使用Azure网站最简单的方法是什么?
  • 最好不要重新部署。

我在网络下找到了IP限制,但似乎你可以只使用白名单,而不是黑名单。

azure web ip blacklist
1个回答
2
投票

我这样做的两种方式:

在web.config中使用<ipSecurity>标记

这不是特定于Azure的,但可以在Azure Web App中使用。好处是你不必重新部署。缺点是触摸web.config将导致您的Web应用程序被回收。这对您来说可能是也可能不是问题。

这是一个例子:

<system.webServer>
   <security>
      <ipSecurity>
         <add ipAddress="5.124.39.210" />
      </ipSecurity>
   </security>
</system.webServer>

这将阻止IP地址为5.124.39.210的火鸡访问您的站点。您甚至可以选择为受限制的IP(401,403,404)发回的HTTP响应代码。

有关详细信息,请访问see here

滚动你自己

如上所述,关于运行web.config路由的一个坏处是,当您的web.config被修改时,它将需要重新启动应用程序。我还保留了从数据库表中定期读取的受限IP地址的内存缓存。根据我的HttpApplication子类的Application_BeginRequest方法中的黑名单检查传入请求。

它有点像:

 protected void Application_BeginRequest(object sender, EventArgs e)
    {
       //our own singleton that caches blacklisted IP addresses
       var webSecurity = new CustomWebSecurity();

       var clientIp = Request.UserHostAddress;

       if (webSecurity.IsInBlackList(clientIp))
       {
                Response.Clear();
                Response.StatusCode = 403;
                Response.Status = "403 Forbidden";
                Response.End();

                return;
       }
    }
© www.soinside.com 2019 - 2024. All rights reserved.