Visualizing .NET 8 Blazor Component Render Locations

The New World of .NET 8 Blazor originally allowed a choice of either Server or WASM (browser client) rendering, but this was an exclusive choice which applied across an entire application. Many things behave differently depending on where they are running, but there was no ambiguity within a single app. Now that .NET 8 is beginning to support the “Blazor United” concept of mixed rendering modes within an application, including adding a third option to statically pre-render in the style of Razor Pages, different parts of your application may render in different places, and can even switch modes on the fly at runtime!...

October 17, 2023 · 6 min · 1090 words · John Bowen

Adding Descriptions to Swagger Generated OpenAPI Documentation

Enhancing API Documentation Swashbuckle tooling for Swagger provides an easy way to document APIs in ASP.NET Core with out of the box functionality that creates a lot without additional customization. The OpenAPI spec allows for a lot of additional description to be included, and by annotating your code in appropriate places the Swagger generation can automatically fill these for you. Many of these additional descriptions also show up in the automatically generated Swagger UI....

September 30, 2023 · 7 min · 1327 words · John Bowen

Embedding appsettings.json Files for Single File Publishing

Appsettings.json Files The configuration system in ASP.NET Core is a flexible way to manage settings, with each of the different providers made available to apps as a unified IConfiguration object. Under normal circumstances adding settings to appsettings.json and environment specific appsettings files is an easy way to configure an app being deployed as a container or set of files on a web server, while also being flexible at development time. In other cases an app needs to be deployed as a single package with a fixed set of configuration settings included that shouldn’t be editable by end users....

August 20, 2023 · 4 min · 840 words · John Bowen

Resolving Client IP Addresses in .NET with Azure Front Door

The X-Forwarded-For Header For situations where knowing the originating public IP (or host name) of a request is needed, .NET provides the Connection property on HttpContext, with a RemoteIpAddress value. Under normal circumstances this is set directly from the incoming request. For example, when running locally under Kestrel this will normally show up as [::1] (IPV6 localhost). Often, modern web apps aren’t serving requests directly but through proxies that can provide security, scalability, or other benefits, like an Azure Front Door CDN....

May 24, 2023 · 6 min · 1187 words · John Bowen

Auth Token Configuration in YARP

The YARP reverse proxy library provides an easy way to forward API calls through an intermediary service. It can be particularly useful for BFF services for front end clients. By default, API requests are forwarded with their existing headers, which can be a problem if the end API requires an auth token that isn’t available to the originating client. In the case of a BFF the API call will generally originate at the client side application running in untrusted browser space which will be using cookie authentication to the service and so won’t have a token to send....

January 12, 2023 · 4 min · 839 words · John Bowen