Thomas Ardal

Thomas Ardal

Denmark
225 posts
NLog Tutorial - The essential guide for logging from C#

TOCWhen NLog originally came out, I was hooked. Such a step up from the world of log4net. Then Serilog came out and I lost track of the progress on NLog. For years I even considered it dead. Boy was I wrong. NLog has developed impressively over the years and offers ...

Cross-site request forgery (CSRF) with ASP.NET Core and AJAX

ASP.NET Core comes with built-in support for cross-site request forgery (CSRF) checks in both old school form posts and AJAX requests. I believe the examples in the official documentation is hard to understand and requires you to change every request made through jQuery or similar frameworks to make server ...

Upload and resize an image with ASP.NET Core and ImageSharp

While migrating our web app to ASP.NET Core, I had to find a new way for the user to upload and resize a profile photo. We used the WebImage class in ASP.NET MVC, which unfortunately isn't available in Core. In this post, I will show you how I ...

The ASP.NET Core security headers guide

TOCThree years ago I wrote a tutorial about security headers in ASP.NET MVC. A lot happened since then and ASP.NET Core is the framework everyone should be on eventually. Time for an updated version for Core! I'll try to recap the different security headers in the post. If ...

ASP.NET Core middleware with Roslyn Analyzers - Part 2

This is the second post in the series about Roslyn analyzers with ASP.NET Core middleware. If you haven't read part 1 already, go ahead a do that for a general introduction. In this post, I'll continue the example from the first post and start looking at the order middleware ...

Generate a PDF from ASP.NET Core for free

No matter what system I have been working on, generating PDF files already snuck in somehow. Whether it is generating an invoice or a report of data, PDF files are still an essential part of most web applications. In this post, I'll show you how to generate a PDF file ...

ASP.NET Core middleware with Roslyn Analyzers - Part 1

ASP.NET Core middleware is a clever way to configure features like authentication, routing, and error logging in ASP.NET Core. Adding the different pieces of middleware and in the right order can be quite a nightmare, though. In this post, I'll show you how Roslyn Analyzers can help. Middleware ...

How to send emails from C#/.NET - The definitive tutorial

TOCI just answered some questions from a friend of mine about a subject that I believe would fit within my how-to-series of posts. That's where I try to come up with updated answers to common C# challenges like converting between formats or saving content to a file. For today's post, ...

C# how to convert a string to int

TOC Time for a new post in my how-to series. In this series, I try to provide updated answers for common .NET/C# questions. I found that when googling common terms like "convert string to int", "write to a file", and similar, I would often get outdated StackOverflow answers, showing ...