WHAT’S NEW IN .NET8

DOTNET 8 New and Efficient Way to Check IP is in Given IP Ranges

Sibeesh Venu

--

The .NET 8 has introduced a new type IPNetwork with a Contains method. It retruns true if the given IPAddress is part of the IP network. Otherwise, returns false.

DOTNET 8 New and Efficient Way to Check IP is in Given IP Ranges

In our last post we have seen how we can restrict the access to your application by implementing IP restrictions using ActionFilterAttribute but we were checking the IP addresses and was missing a feature to support the IP Ranges. The good news is that the .NET 8 has a new and efficient way to do this. Here in this post, we will see how we can implement the same. Let’s begin.

Source Code

You can also see the codes in this repository.

Enablling .NET8 for Your Application

As you might have already guessed, the first step is to download the .NET8 from here. Let’s now change the TargetFramework in our both DotNetIpFilter.csproj and DotNetIpFilter.Test.csproj files. You can get the application code from the repositroy mentioned above.

<TargetFramework>net8.0</TargetFramework>

You will also need to update your Microsoft.AspNetCore.OpenApi package to .NET8.

Enable Preview .NET 8 in Visual Studio 2022

If you are trying to create a new application using Visual Studio 200, you may be missing an option to chose the .NET8 framework, to mak sure to get this option, do the following.

1. Update your Visual Studio 2022

2. Go to Tools -> Manage Preview Features

.NET 8 Manage Preview Features

3. Select checkbox Use preview of the .NET SDK (requires restart)

4. Make sure to restart after enabling this

Use .NET Previews of the .NET SDK

Use .NET8 Contains Method from IPNetwork

--

--

Sibeesh Venu

An engineer by profession and writer by passion. Author at Sibeesh Passion, Microsoft MVP (2016–2022). Software Engineer @ Microsoft