0

I have converted my website from ASP.NET to ASP.NET Core.

In the original ASP.NET project, I had restricted some IPs via the webconfig like this:

<system.webServer>
  <security>
    <ipSecurity allowUnlisted="true">
        <add ipAddress="92.127.176.55" />
        <add ipAddress="92.124.0.0" subnetMask="255.252.0.0" />
    </ipSecurity>
  </security>
</system.webServer>

Is it possible to restrict IPs in the ASP.NET Core project in a similar way?

Jamie Taylor
  • 1,644
  • 1
  • 18
  • 42

1 Answers1

2

You can also use ZNetCS.AspNetCore.IPFiltering to block some ip address; //install using command

PM> Install-Package ZNetCS.AspNetCore.IPFiltering

//In Startup.cs ConfigureServices

 services.AddIPFiltering(this.Configuration.GetSection("IPFiltering"));

// In Startup.cs Configure add

  app.UseIPFiltering();

// In appsetting.json add IPFiltering

"IPFiltering": {
    "DefaultBlockLevel": "All",
    "HttpStatusCode": 404,
    "Whitelist": [ "192.168.0.10-192.168.10.20", "fe80::/10" ],
    "Blacklist": [ "192.168.0.100-192.168.1.200"],
    "IgnoredPaths": [ "GET:/ignoreget", "*:/ignore" ]
}