Thomas Ardal

Thomas Ardal

Meet Thomas, the founder and developer behind elmah.io. Thomas blogs about everything technical from C# and ASP.NET Core to machine learning.

Denmark
320 posts
ASP.NET Core middleware with Roslyn Analyzers - Part 2

Part 2 of a Roslyn analyzer series builds UseElmahIoOrderAnalyzer.cs (diagnostic ID EIO1002), scanning the Configure method of a Startup class to warn when UseElmahIo middleware is registered before UseDeveloperExceptionPage or UseExceptionHandler, using RegisterCodeBlockStartAction. ...

Generate a PDF from ASP.NET Core for free

A free alternative to paid PDF components like NReco.PdfGenerator: install Wkhtmltopdf.NetCore, wire it up with AddWkhtmltopdf in ConfigureServices, place the wkhtmltopdf executable in a wkhtmltopdf/Windows folder, then inject IGeneratePdf into a controller to render a Razor view to PDF. ...

ASP.NET Core middleware with Roslyn Analyzers - Part 1

Part 1 of a Roslyn analyzer series: from Visual Studio's Analyzer with Code Fix template, builds CallUseElmahIoAnalyzer.cs (diagnostic ID EIO1001) using RegisterCodeBlockStartAction to flag a Startup.Configure method that never calls UseElmahIo, citing Andrew Lock on middleware ordering. ...

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

Compares C#/.NET email-sending options in code: the built-in System.Net.Mail SmtpClient and MailMessage classes over SMTP port 587, generating a Google Workspace App password for Gmail SMTP, plus AWS Simple Email Service, Mandrill, and Azure as alternatives to hosting your own SMTP server. ...

C# how to convert a string to int

Compares three ways to convert a string to int in C#: int.Parse (throws FormatException on bad input), int.TryParse (returns a bool with no exception needed, the recommended approach), and Convert.ToInt32, whose char overload silently converts the character 1 to its UTF code 49, not the number 1. ...

Publish a self-contained .NET app on Azure DevOps

Walks through fixing an Azure DevOps pipeline that fails to build a self-contained .NET 5 console app for win-x64: adding a RuntimeIdentifiers element to fix NETSDK1047, then resolving a 401 from a custom NuGet feed by adding --no-restore to dotnet build and --no-build to dotnet publish. ...

ASP.NET Core request logging middleware

Builds a minimal RequestLoggingMiddleware for ASP.NET Core that logs one structured message per request (method, URL, status code) via Microsoft.Extensions.Logging, wired up with app.UseMiddleware, and paired with Elmah.Io.AspNetCore.ExtensionsLogging to attach HTTP context to each entry. ...

Effective Error Logging in Windows Forms Applications with C#

Covers three layered approaches to catching errors in a C# Windows Forms app: try/catch blocks, the Application.ThreadException event for unhandled UI-thread exceptions, and a GlobalExceptionHandler wired to AppDomain.CurrentDomain.UnhandledException, logging to a file or Serilog, NLog, elmah.io. ...

The ultimate guide to secure cookies with web.config in .NET

Fourth in an ASP.NET security series: shows how to stop XSS from hijacking the .ASPXAUTH authentication cookie by setting requireSSL and httpOnlyCookies in web.config httpCookies element (or Secure/HttpOnly on an HttpCookie in C#), plus disabling TRACE requests to prevent Cross-Site Tracing. ...