Kristoffer Strube

Kristoffer Strube

Meet Kristoffer, one of the core developers behind elmah.io. Kristoffer writes highly technical posts about anything from C# and LINQ to Blazor.

Denmark
25 posts
How to fix Blazor WASM base path problems

Fixes the 404 on blazor.webassembly.js when a Blazor WASM SPA is published to a subdirectory like GitHub Pages, replacing the static base href tag with a JavaScript snippet that dynamically sets the base path from window.location.pathname, working on localhost and nested routes alike. ...

How to add User-Agent header to HttpClient in .NET

Explains setting a User-Agent header on HttpClient in .NET/C# with ProductInfoHeaderValue, covering per-request headers via HttpRequestMessage, default headers via DefaultRequestHeaders, and HttpClientFactory, plus the bot format .NET/5.0 ScraperBot/1.0 (+http://example.com/bot.html). ...

Call anonymous C# functions from JS in Blazor WASM

Extends a Blazor WASM wrapper for the Popper.js library to invoke C# callbacks like onFirstUpdate from JavaScript, using JSInvokable methods on an Options class and a DotNetObjectReference passed into IJSRuntime.InvokeVoidAsync, with IDisposable cleanup on the Popper class to avoid memory leaks. ...

How to send push notifications to a browser in ASP.NET Core

Implements web push notifications in ASP.NET Core using the VAPID standard, covering building a minimal PWA with a manifest.json and ServiceWorker.js, generating a VAPID public/private key pair stored in appsettings.json, and subscribing the browser to the push service to send native notifications. ...

Wrapping JavaScript libraries in Blazor WebAssembly/WASM

Shows how to wrap the Popper.js positioning library in a .NET Core 3.1.300+ Blazor WebAssembly project, creating a C# Popper class that injects IJSRuntime and calls InvokeVoidAsync against a PopperWrapper.js helper file, mapping ElementReference parameters through to Popper.createPopper. ...

How to secure ASP.NET Core with OAuth and JSON Web Tokens

Implements the OAuth 2.0 Authorization Code flow with JSON Web Tokens directly in ASP.NET Core, skipping IdentityServer4, OpenIddict, and ASOS, with a walkthrough of an Authorize-protected action validating response_type, client_id, and client_secret before issuing a code exchanged for a JWT. ...

Paid subscriptions with ASP.NET Core and Stripe Billing

Compares Stripe two payment options for SCA-compliant recurring billing in ASP.NET Core after Europe September 2019 SCA mandate: redirect-based Checkout versus embeddable Stripe.js, settling on Stripe.js so one form offers Monthly and Yearly subscription plans via radio buttons. ...

Common exceptions and fixes in Entity Framework and SQL Server

Diagnoses three SqlClient.SqlException messages in Entity Framework and SQL Server: Login failed for user, fixed via Integrated Security and auth-mode checks; Cannot open database, fixed via myContext.Database.EnsureCreated(); and network/instance-not-found errors tied to SSMS remote settings. ...

Convert images to WebP with ASP.NET Core - Better than png/jpg files?

Shows how to convert uploaded PNG/JPEG images to Google WebP format (up to 34% smaller) in ASP.NET Core MVC using the ImageProcessor and ImageProcessor.Plugins.WebP NuGet packages, validating IFormFile uploads by content type, and using the HTML5 Picture tag as a fallback for Safari. ...