Posts

String Interpolation in C#

String interpolation has been around since C# version 6, so it is not exactly new, but even so, I sometimes encounter developers who are not familiar with the format. In this article, we will explore some of the features of string interpolation; the good, the bad and the ugly. Before the introduction of string interpolation, you only had two choices when it came to compiling a string with variable data. You either had to concatenate the string and the variables together, or you had to use composite formatting, as shown below. class Program { static void Main(string[] args) { string name = "Clark Kent"; DateTime now = DateTime.Now; // Concatenate var concatMsg = "Hi there, " + name + ". Today is " + now.DayOfWeek + " and the time is " + now.ToString("HH:mm") + "."; Console.WriteLine(concatMsg); // Composite var co...

.NET Core JWT Authentication

Image
In today's article, I will show you an easy implementation of JWT Bearer Tokens in .NET Core.  To keep things simple, I will not be connecting to any persistent storage for user management, but you are welcome to expand on this example. So, what are JWT Bearer Tokens?  According to the official description, "JWT (JSON Web Token)  is an open standard ( RFC 7519 ) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object."  This is a fancy way of saying that by using bearer tokens, you can secure your applications using a simple JSON object in a nice, compact manner which is great for web applications. But you are here to see some code, right?  Let's dive in... We start off by creating a new .NET Core Web API application: Once our project is created, we ...