Basic Authentication in ASP.NET Core example

Download a Basic Authentication example in ASP.NET Core with Minimal API and controllers examples.

You can learn more by reading our Basic Authentication tutorial, or watching this video.

Download the code example

You'll need to fill out the code example form. We will send you an email where you can download the code example.

Software

This is the software that will need to be installed onto your machine.

The application

Open up RoundTheCode.BasicAuthentication.slnx. The project should open in Visual Studio 2026.

Run the application.

You can use Postman to test the API endpoints with these endpoints using HTTP GET:

  • Minimal API - https://localhost:7260/api/products/2

  • Controllers - https://localhost:7260/api/categories/2

In the Authorization tab, set the following options:

  • Authorisation Auth Type: Basic Auth

  • Username: roundthecode

  • Password: roundthecode

The requests will return 200 OK. If you change the username, password, or the Auth Type to something different, it will return 401 Unauthorized.