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
Fetching GitHub content from C#

Builds a GitHubContentService in ASP.NET Core that uses HttpClientFactory to call GitHub's contents API, decodes the Base64-encoded response, converts Markdown to HTML with Markdig, and caches results for an hour via IMemoryCache to avoid hitting GitHub's API rate limit. ...

How to integration test exception handlers in ASP.NET Core

Implements a MyExceptionHandler class using ASP.NET Core's IExceptionHandler interface, then writes a full-pipeline integration test with NUnit and WebApplicationFactory against a /throw endpoint to verify the middleware returns the expected 500 JSON, instead of mocking HttpContext directly. ...

Automate JavaScript scanning with Retire.js in Azure DevOps

Runs Retire.js, a CLI vulnerability scanner by Erlend Oftedal, against an ASP.NET Core 3.1 MVC project's wwwroot libraries to catch a jquery-validation 1.17.0 ReDoS flaw (CVE-2021-21252), then wires the same scan into an Azure DevOps build via a custom extension so vulnerable JS fails the pipeline. ...

How to run code coverage of .NET code on Azure DevOps

Walks through adding code coverage to an Azure DevOps YAML pipeline for .NET 9: install the coverlet.collector NuGet package, enable XPlat Code Coverage in a DotNetCoreCLI@2 test task, then use ReportGenerator to turn the raw XML into a readable report published as a build artifact. ...

Common HttpClient tasks you're googling or asking ChatGPT

Collects concrete HttpClient recipes for .NET: set a User-Agent with ParseAdd, enable GZip/Deflate AutomaticDecompression on HttpClientHandler, disable SSL validation via ServerCertificateCustomValidationCallback, send typed payloads with PostAsJsonAsync/GetFromJsonAsync, and add Polly retries. ...

Adding Cloudflare Turnstile to an ASP.NET Core website

Recounts why elmah.io moved from Google reCAPTCHA to Cloudflare Turnstile after reCAPTCHA shifted to Google Cloud, then shows the ASP.NET Core integration: a Managed-mode widget in the Cloudflare dashboard, wiring turnstile.render with a site key and token callback, and passing the token on submit. ...

The NuGet packages we use to build elmah.io revisited

Details NuGet packages elmah.io added since its last stack review: Azure.AI.OpenAI and Microsoft.SemanticKernel for its Bugster chatbot, the Azure.* rewrite (Azure.Storage.Blobs, Azure.Messaging.ServiceBus), HtmlAgilityPack for uptime's canonical checker, and IPNetwork2 for CIDR-based IP filtering. ...

Revisiting improved HTTP logging in ASP.NET Core 8

Revisits ASP.NET Core 8's HTTP logging: setting up AddHttpLogging and UseHttpLogging, merging separate request/response log entries into one message via the new CombineLogs option, and writing a custom IHttpLoggingInterceptor called IgnoreLoggingInterceptor to skip noisy .css and .js requests. ...

Understanding .NET stack traces - A guide for developers

Breaks down a NullReferenceException stack trace line by line - exception type, message, the three-space call stack indentation, and file/line source info - then moves into combining inner and aggregate exceptions. ...