Articles

The Case Against Generative AI
Generative Artificial Intelligence (AI) tools are awesome and I use them every day. They are massive boost to coding and they make learning new things much easier. However, there are a lot of claims about AI that seem to be far ahead of where the technology is… 
Securing an ASP.NET Website with OpenID Connect
The Microsoft ASP.NET middleware makes it straightforward to implement OAuth2 and OpenID Connect flows in an ASP.NET Website. In this article we will go through the code and configuration required to implement the authorization code flow using the standard… 
Using Microsoft SQL Server Profiler to Capture Entity Framework Queries
Microsoft SQL Server Profiler is an excellent tool for getting information about the SQL being built and run by Entity Framework against your Microsoft SQL Server database. SQL Server Profiler installs with SQL Server Management Studio (SSMS) but is a… 
C# JSON Parsing with Json.NET and JObject
Parsing JSON using C# can be a fiddly but with Newtonsoft’s Json.NET library it becomes a breeze. The library provides a number of types for parsing JSON which I find useful for hacking together tools to help work with big JSON structures. However, it can… 
How to Mock HttpRequestData for Unit Testing in Azure Functions
It turns out that unit testing Azure Function Http Triggers is not straightforward. In particular, isolated functions that use the Built-in HTTP model . The built-in model passes HttpRequestData to the Run method and returns a HttpResponseData object… 
Migrate Azure DevOps Pipeline Variables using Azure CLI and PowerShell
Recently I’ve been working on a project which has an Azure DevOps YAML pipeline with all environment config added using pipeline variables . The variable groups feature provides a much better way of grouping and managing pipeline config so I decided to… 
Global Error Handling in ASP.NET Core 8 with IExceptionHandler
Typically in a ASP.NET Core Web application our code may throw an unhandled exception for many unknown reasons. Consequently its advisable to wrap application code in a global exception handler using a filter or some custom middleware. ASP.NET Core… 
Using Serilog and .NET to Write Logs to Splunk HTTP Event Collector
Splunk provides an HTTP endpoint, known as an Event Collector, which can be used to POST log messages directly to the Splunk database. In this article we see how Serilog can be used in an ASP.NET Core Web API to write messages into Splunk using the HTTP Event… 
Getting Started with the Azure Blob Storage .NET Client Library
Azure Blob Storage is Microsoft’s cloud storage solution for storing massive amounts of unstructured data. The solution is composed of three key resources: storage accounts, containers and blobs. A blob represents a file and a container organizes a set of… 
How to Create Responsive Layouts Using Bootstrap 5.2 Grid
The Bootstrap Grid system offers a fast and efficient way to create responsive, structured layouts with minimal effort, ensuring consistency, simplifying responsiveness, and handling cross-browser compatibility. The grid system is designed so that smaller less… 
Automating Your Windows Terminal With A PowerShell Profile
I’m a regular user of the Windows Terminal to speed up the manual tasks that are required during the software development process. I’ve found PowerShell’s $PROFILE script very useful for adding automation code which is loaded every time a PowerShell session… 
3 Tips To Get More From Postman
The Postman API client is easy enough to get started with creating collections and managing basic API calls. However there is a lot of functionality built into the app which can take a while to discover. Here are 3 features that I find particularly useful.… 
How to Deploy MockServer to Azure using Terraform and Docker
Deploying applications using Terraform and Docker makes it extremely quick and easy to setup software in Azure. In this tutorial I use the MockServer docker image to deploy an application that can be used to mock REST API calls during development phases… 
Setting Up a Mock OAuth2/OIDC Server with IdentityServer4 and Docker
The Soluto Github organisation has wrapped up IdentityServer4 in a docker image which can be used to provide an OAuth2 and OIDC standards compliant server for development and testing scenarios. oidc-server-mock Getting Started The following docker compose file… 
C# .NET 8.0 Connecting to Sybase ASE 16 via ODBC driver
It’s possible to use .NET Core and C# to connect to SAP’s Sybase ASE database using the AdoNetCore.AseClient library. It provides… a .NET Core native implementation of the TDS 5.0 protocol via an ADO.NET DB Provider However its not actually an official SAP… 
Displaying Data With ASP.NET Core and jQuery datatables.net
Software systems often have to display a lot of data and people expect functionality like pagination, searching and sorting by default. The jQuery plugin datatables.net transforms a basic HTML table with a few lines of code into a fully functional data grid… 
ASP.NET Core Data Driven Bootstrap Treeview
Bootstrap provides some nice, clean components for structuring page content. You can also combine various styles to create new effects. In this article we will see how to combine List Groups with the Collapse plugin to create a tree like representation of… 
Setup Keycloak OAuth2/OIDC Provider for local dev
Keycloak is a full featured open source Identity and Access Management solution. Its written in Java and deployed with Docker meaning you can get up and running in minutes. It is ideal for for local development scenarios where we need a standards compliant… 
Dockerize an ASP.NET Core Application
Visual Studio provides excellent support for docker containers, but this does mean some of the complexities of the technology can get masked. In this tutorial we walk through the basics of building a docker container for a simple ASP.NET Core Web Application… 
ASP.NET Core Razor Pages Simple Web Template
Visual Studio 2022 provides a template for creating an empty ASP.NET Core application. Although this template requires a bit of work to get a Razor Pages website up and running, by using the empty template we can include only the libraries and template code… 
Adventure Works Databases for Sql Server
Microsoft released a sample database which can be used to explore and practice using the various features of Sql Server. Adventure Works is a fictitious, multinational bicycle manufacturing company. The database is an enterprise solution which covers Sales… 
Getting started with EntityFrameworkCore
I while ago, I posted about setting up Entity Framework 6 Code First migrations in an MVC 5 Project. These days, its all about dotnet core, and whilst the process is very similar, I thought I would write another detailed walk through so that I can hit the… 
Generating C# Clients using Swagger and Autorest
Autorest is a great tool for automating the creation of clients from Swagger or Open Api definition files. The resulting code can be dropped into a project and shareable client code can be distributed. Installation First install node and then, using npm we… 
Understanding the C# Linq SelectMany Operator
The Linq operator SelectMany has always confused me a bit, and yesterday I came across it in some code so had to actually try to understand it. Simple put, SelectMany selects out all children from a collection of parents in a one to many parent child… 
Turning on internal logging for log4net
Turning on internal logging for log4net is straight forward and provides a detailed information about the many issues that may occur. Add in Debug App Setting There is only two things that you need to do... first up add in the following app setting: \<add key… 
Setting up Powershell console profile
In my previous post I talked about setting up vim plugins. I've been using vim on the commandline quite a bit now and have found a couple of useful commands that I like to have setup to make use a bit easier. The Powershell $profile Powershell has the $profile… 
Setting up Vim Plugins on Windows
I've been using VsVim the vim Visual Studio plugin and I really like how much easier it makes coding when your fingers can live on the home keys more. Recently I started working through Roy Osheroves Vim Hates You course and learning loads more tricks and… 
Setting up a Selenium/Specflow Acceptance Test Project
I really appreciate the value in using Selenium and Specflow to write a suite of browser based tests to validate a software application. These tests unequivocally confirm that the acceptance criteria is met and the application functions as desired. I wrote a… 
Creating Custom Powershell libraries
Powershell is a very powerful tool for automating tasks. Creating your own nuget repository that hosts powershell modules is a great way to distrubute powershell scripts, but it can be a bit fiddly to setup. When creating your own modules, it can be quite… 
Uninstalling Visual Studio using MS Total Uninstall
Uninstalling Visual Studio can be a real challenge, and my old PC at home is full with versions 2012/13/15. After a brief bit of googling I found a very useful tool which seemed to do the job and freed up 20gb of space on my machine. The Visual Studio… 
Scripting the Installation of Powershell 4.0
I got a bit fed up with upgrading PowerShell on a number of different servers so decided to write a script to automate the task. I appreciate that it doesn’t take long to click download and install but after using chocolatey you start to realise how easy it… 
Parsing Visual Studio Files with Powershell
Most companies have some pretty complicated legacy code bases with a multitude of applications and shared libraries. It can be quite difficult to see how the solutions and projects fit together. With the push towards devops and microservices it’s nice if we… 
Using Markdown in ASP.NET
Recently I was tasked with adding some CMS style functionality to a customers site. Rather than reinvent the wheel by doing my own pattern matching etc, I decided to use some markdown to do the hard work. I naively thought that it would be easier to implement… 
Adding ASP.NET Identity 4.5 to an Existing Application
Watching videos about putting ASP.NET websites together, it always looks really nice and straight forward, it demos really well. Back at the office, faced with some real world requirements things never seem that simple. To this end I decided to try to setup… 
Visual Studio 2013 WIF 3.5 STS Template
The Windows Identity Foundation (WIF) 3.5 provided some Visual Studio templates to create a Secure Token Service (STS.) Unfortunately these were not available in Visual Studio 2013 and also, they actually created a Web Site rather than a Web Application. I… 
Clicked checkbox does not post back to the server
Recently I got a bit stuck trying to do the simple task of set some values on a checkbox. The form was quite complex and I was finding that checking a checkbox to signify a "FollowUp" had occurred was not being posted back to the server. It took quite a bit of… 
JavaScript Property Descriptors
In a previous post, I mentioned how a JavaScript object can be thought of simply as a collection of properties. But a property in JavaScript is more than just a value - property’s themselves have… well properties. The properties of our object properties are… 
Creating objects in JavaScript
I've been messing around with JavaScript for years now, but have been more of a JQuery hacker. I thought it was time to learn the language properly as its becoming increasingly common in web applications these days. This is a bit of a dummies guide, but I… 
Setting up Rhino Mock Stubs
A quick template below for the basic setup of Rhino Mocks Stubs...  
Shrinking log files on SQL Server 2008 R2
You know your having a bad day when you have to logon to a server to start running SHRINKFILE commands to free up disk space. Recently our Team City builds will start failing because an application API is down and when we track that through, we find that a Sql… 
Auto suggest with Twitter typeahead
Twitter's typeahead JQuery plugin provides excellent auto suggest functionality that you can use on text boxes. It transforms a rudimentary lookup facility into a very useful search tool. There's a great example on the project homepage ... Getting Started I… 
Enabling Nuget Automatic Restore
There are three ways that Nuget updates packages: Automatically MSBuild-Integrate Using the command line Automatically As of Nuget version 2.7 the package restore should just all work! There are two settings which when checked means that new packages will… 
Calling Web APIs with Powershell
You go along way by calling apis at the command line. Powershell provides the following methods that you will find useful... Invoke-RestMethod Invoke-WebRequest ConvertTo-Json ConvertFrom-Json Examples of simple api web request Examples using the IE Browser… 
Using HttpClient to access API resources
Oftentimes we will have the need to call into an API to load resources. HttpClient class provides in the System.Net namespace provides all the required functionality to interact with an API in the usual ways. In the example below, we have a C# POCO called… 
Protecting against Cross Site request Forgery (CSRF)
Cross Site Request Forgery, or CSRF as its often known, is a common security vulnerability which describes an attacker attempting to cause state changes on a server by tricking a victim into sending an undesired request from an authenticated session without… 
ActionResults in ASP.NET MVC 5
In ASP.NET MVC 5  ActionResult  classes are used to return data from the controller classes to the views. There are 15 different sub classes that can be used in various situations depending on your scenario... Its usual to return the base class ActionResult… 
Scripting Database Table Create SQL using Powershell
PowerShell is quite high on my list of languages that I dip in and out of without really knowing nearly well enough. One of things that I have found myself doing quite regularly is trying to script SQL for creating tables. This is quite straight forward using… 
Setting up log4net in ASP.NET MVC
I seem to burn far to many hours trying to do the relatively simple task of setting up log4net on a project. Well step one is easy enough, install through nuget . Next... Add web.config settings I like to create a separate config file for log4net because it… 
Unit Testing Entity Framework 6 DbContext
The Entity Framework version 6 has good unit testing possibilities and the documentation provided by MSDN provides a good starting point... Testing with a mocking framework Testing with your own test doubles The main thing to remember is that you need to… 
A Simple 3 Layer Architecture
A while ago I talked about the standard architectural approach at work . The truth is I'm not completely taken with putting an API in, particularly when its a small application. So how would an application look without the API? Well, I know all of the… 
Using Selenium API to find HTML page components
Once you have setup your acceptance tests using the page object pattern as described in an earlier post , and you continue to write scenarios you will end up needing to use the Selenium API to find HTML components as part of the acceptance test scenarios. The… 
Entity Framework Code First to an Existing Database
Recently I had a need to create an entity model from an existing database so started adding an edmx as I had done so many times before in this scenario. Then I remembered reading on the Entity Framework documentation website that its actually possible to… 
Writing Acceptance Tests using SpecFlow & Selenium
Selenium and SpecFlow are pretty straight forward to get to grips with individually, but on larger projects when the page object pattern is used things start to get a little more complicated. I find it useful to think about three layers when organizing the… 
Getting Started with Entity Framework Code First
The documentation  for the Entity Framework provides thorough introduction, in this post I start with the basic tutorial for code first with a view to setting up an application I can use to practice some technologies and techniques on in the future… 
MVC Unit Testing Asserts with Rhino Mocks
When I first started learning to use mocking frameworks I was lucky enough to start on Moq which was nice and simple. Whenever I needed to know something there was one single google code page which told everything. Nice! Rhino Mock by example I find hard work… 
ASP.NET MVC Standard Application Architecture
At work we have started moving towards a standard .NET application architecture for most of our apps. This uses MVC 5 website with a REST client talking to a Web API 5. When you open a visual studio solution, as a minimum you see the following projects… 
ASP.NET MVC Uploading and Downloading Files
Uploading files is pretty straight forward with ASP.NET MVC 5, but there are few things to be aware of to make things go a bit smoother. Razor View The view needs to have the enctype set as shown below. Also, if you are using the TextFor HtmlHelper, make… 
Mocking the Controller Context using Rhino Mock
When using ASP.NET MVC 5, its easy to write unit tests around the framework due to the various abstractions provided. Stephen Walther  provides a good overview of the different objects. Whenever you need to interact with the request, response, session or…