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

Controlling Execution Flow While Producing IAsyncEnumerable Sequences

Producing IAsyncEnumerable The introduction of IAsyncEnumerable to C# allowed for simplifying a lot of scenarios that used to require a lot of code to get async behavior similar to an equivalent synchronous scenario. The await foreach construction specifically makes the consumption side almost trivial. The combination of the delayed execution of IEnumerable and asynchrony does add some complexity though, which can often come into play on the side of producing the async collection and trying to build control flow or error handling into the process....

April 26, 2023 · 13 min · 2597 words · John Bowen

Structuring a Maintainable Console App with System.CommandLine

System.CommandLine as a Starting Point Writing console apps from scratch can involve a lot of messing around with boilerplate code just to get basic user input and take advantage of basic features like logging and configuration that come more or less for free in an AspNetCore web app. Adding in features normally found in command line apps like parsing input parameters commands and options or displaying help text to guide users adds on even more work before getting to the app’s core functionality....

February 24, 2023 · 7 min · 1310 words · John Bowen

Roslyn and the future of .NET languages – Language Features

Boston Code Camp 22 materials: Slides | Language Features Demo Code | Post on Extensions The new Visual Studio 2015 Roslyn language features include a grab bag of nice changes to help make code more compact and readable. This isn’t an exhaustive list but some of my favorites. Getter only and initialized auto-properties public string Name { get; } = "John"; This is a much simplified way to create readonly properties, which previously required a full property with a backing field declared as readonly....

November 22, 2014 · 2 min · 355 words · John Bowen

Roslyn and the future of .NET languages – Extensions

Boston Code Camp 22 materials: Slides | Extension Demo Code | Post on Language Features With the new code editors in Visual Studio 2015 now written around the Roslyn compiler a whole new level of extensibility is available both for built in features and user created extensions. If you’ve worked with Visual Studio extensibility before a Roslyn extension can a big improvement both in ease of coding and end user experience....

November 22, 2014 · 2 min · 414 words · John Bowen