IpShieldMiddleware 1.0.0

dotnet add package IpShieldMiddleware --version 1.0.0
                    
NuGet\Install-Package IpShieldMiddleware -Version 1.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="IpShieldMiddleware" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IpShieldMiddleware" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="IpShieldMiddleware" />
                    
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 IpShieldMiddleware --version 1.0.0
                    
#r "nuget: IpShieldMiddleware, 1.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.
#:package IpShieldMiddleware@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IpShieldMiddleware&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=IpShieldMiddleware&version=1.0.0
                    
Install as a Cake Tool

IpShieldMiddleware

IpShieldMiddleware is a lightweight ASP.NET Core middleware for IP-based request filtering. It allows whitelisting or blacklisting specific IP addresses with customizable error messages and logging.

This middleware intercepts incoming HTTP requests and performs IP filtering based on the configured whitelist and blacklist IP's.

-Requests from whitelisted IPs are allowed.
-Requests from blacklisted IPs are blocked, returning a response of 403 (Forbidden) with the default message in case no custom message was provided.

🔧 Features

  • ✅ Whitelist specific IP addresses
  • 🚫 Blacklist unwanted IP addresses
  • ✍️ Optional custom error messages with IP placeholder ({IP}) for both response and logging (if not provided a default message will be used)
  • 📝 Built-in logging support
  • 📦 Plug-and-play for ASP.NET Core projects

📦 Installation

dotnet add package IpShieldMiddleware

🚀 Getting Started

builder.Services.Configure<IpShieldOptions>(options =>
{
    options.WhitelistedIps = new List<string> { "127.0.0.1", "::1" };
    options.BlacklistedIps = new List<string> { "192.168.1.100" };
    options.CustomLogMessage = "This is a custom log message for ip: {IP}";
    options.CustomErrorMessage = "This is a custom response message for ip: {IP}";
});

var app = builder.Build();
app.UseIpShield();

or if you want to keep configs in appsettings

"IpShieldOptions": {
  "BlacklistedIps": [ "192.168.1.10" ],
  "WhitelistedIps": [ "127.0.0.1", "localhost", "::1" ],
  "CustomLogMessage": "This is a custom log message for ip: {IP}",
  "CustomErrorMessage": "This is a custom response message for ip: {IP}"
}

then in your program.cs

builder.Services.Configure<IpShieldOptions>(builder.Configuration.GetSection("IpShieldOptions"));

var app = builder.Build();
app.UseIpShield();
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 was computed.  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
1.0.0 158 5/25/2025