- Home
- .NET code examples
- Basic authentication in ASP.NET Core
Basic authentication in ASP.NET Core
Basic authentication is used in a HTTP request by adding a Base64 encoded username and password to the Authorization header.
What's included?
The code sample will give you the functionality to add Basic authentication into an ASP.NET Core Web API.
In addition, you can read more about Basic authentication so you get a better understanding of how it can be used as part of the OAuth Client Credentials grant type.
The order process
When you purchase the code example, you'll be given a ZIP file that contains all the code files that you can download and extract onto your machine.
Software
This is the software that will need to be installed onto your machine.
- Visual Studio 2022. Version 17.9.4 or above. It will work with the free community version.
- .NET 8 SDK. version 8.0.4 or above.
Open the project in Visual Studio
Open up RoundTheCode.BasicAuthentication.sln in Visual Studio. The start up project should be set to RoundTheCode.BasicAuthentication.WebApi which is the ASP.NET Core Web API.
https://localhost:9902 with the Swagger documentation.
How to use Basic authentication in Swagger
Add the username and password as roundthecode.
Add username and password for Basic authentication in Swagger
Executing the request, the API request should return a 200 response. Everything else should return a 401 response.
Related code examples