DNMH.Security.IpRestriction 9.0.0

dotnet add package DNMH.Security.IpRestriction --version 9.0.0
                    
NuGet\Install-Package DNMH.Security.IpRestriction -Version 9.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DNMH.Security.IpRestriction" Version="9.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DNMH.Security.IpRestriction" Version="9.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DNMH.Security.IpRestriction" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DNMH.Security.IpRestriction --version 9.0.0
                    
#r "nuget: DNMH.Security.IpRestriction, 9.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=DNMH.Security.IpRestriction&version=9.0.0
                    
Install DNMH.Security.IpRestriction as a Cake Addin
#tool nuget:?package=DNMH.Security.IpRestriction&version=9.0.0
                    
Install DNMH.Security.IpRestriction as a Cake Tool

DNMH.Security.IpRestriction

Overview

DNMH.Security.IpRestriction is a .NET library that provides IP restriction middleware for your web applications. It allows you to restrict access to your application based on a configurable list of allowed or denied IP addresses.

Installation

You can install this library using NuGet. Simply run the following command:

dotnet add package DNMH.Security.IpRestriction

This will add IP restriction functionality to your .NET application.

Usage

To use this library, follow these steps:

  1. In your Startup.cs file (or Program.cs for minimal APIs), configure the IP restriction middleware:
builder.Services.AddIpRestriction(options => 
{ 
    options.Global.Deny.Add("192.168.1.1"); 
    options.Profiles["profileKey"].Allow.Add("10.0.0.1"); 
});

And then adds the middleware after the web application is built:

app.UseIpRestriction();
  1. Rely on the Globally configured restrictions that are applied to all requests, or use the [IpRestricted("profileKey")] attribute to apply IP restrictions to specific controllers or actions:
[Route("api/[controller]")] 
[ApiController] 
public class MyController : ControllerBase 
{ 
    [HttpGet] 
    [IpRestricted("myProfile")] 
    public IActionResult Get() 
    { 
        return Ok("Access granted!"); 
    } 
}

License

This library is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.0 132 5/5/2025