James Flower

C# .NET and Web Developer

Posts by James Flower

Using Ghost as a Headless CMS with Static Site Generator and Deploying to Cloudflare Pages

Posted on
5 min read

Most blogging websites are powered by server-side software such as Ghost or WordPress. This is extremely useful since they can support complex post editors, schedule posts to be released later, and allow users to register on the website. I self-host Ghost in a dedicated virtual machine, but this mean that I have no redundancy and if I have to do a reboot of the virtual machine for updates it results in my blog content being unavailable for a few minutes. Eventually, I decided I wasn’t happy wit

Read more...

Setup Gitpod for a .NET 6+ Web App

Posted on
2 min read

Gitpod is a service which provides development environments in the cloud, but a .NET web app will need some extra configuration to make it accessible when running from a development workspace. You can use Gitpod by logging in with an account from a source control provider (such as GitHub or GitLab), and then selecting the repository you would like to use from the list of available repositories. After you have selected a repository, a new workspace is created and the files will be cl

Read more...

Protect Microsoft SQL Server with a Cloudflare Tunnel and Cloudflare Access

Posted on
4 min read

Microsoft SQL Server is a database server engine used in a wide variety of organisations for storing their data. Sometimes, it can be necessary to provide access to this data from remote locations (such as to remote workers, or to services running in remote locations). A Cloudflare Tunnel when combined with Cloudflare Access can provide secure access to a Microsoft SQL Server instance without requiring any ports to be opened or a VPNs to be configured. Introduction In this post, I am goin

Read more...

Setup GitPod for Vue.js Development

Posted on
5 min read

GitPod is a cloud-based development environment which can be used to work with a variety of frameworks, including Vue.js. It is designed to be quick to spin up new instances of a development environment through automated scripts. One of the advantages of this is that it reduces the chance of encountering issues due to differences in environments, and ensures everyone has the tools they need to start working on a project quickly. However, I recently encountered a few issues when attemptin

Read more...

Will WebAssembly (Wasm) replace JavaScript?

Posted on
5 min read

Ever since JavaScript was created in 1995 it has formed a key part of providing interactive experiences on websites. However, since WebAssembly (Wasm) support is now available in major browsers, will it be able to hold out against the competition, or will WebAssembly replace JavaScript as the essential tool for client-side development on the web? I think there are several factors that will drive or slow developers to adopt WebAssembly as a JavaScript replacement. These are, the current l

Read more...

Duplicate Validation Messages with FluentValidation in ASP.NET Core 6 MVC

Posted on
6 min read

Validation is an important step when handling data from a request in ASP.NET Core 6. FluentValidation is a popular .NET library which can make validation your models easier. It allows you to define your validation rules in a single place and integrate custom logic for your validation, which would require you to make a new filter if you used data annotations. However, in ASP.NET Core 6 MVC there was a change in the project template that could result in seeing data annotation produced vali

Read more...

Install a Self-Hosted VPN with PiVPN on a Raspberry Pi

Posted on
6 min read

The Raspberry Pi is a very useful and versatile computer you can use to host and run a variety of services from your own home. An example of this is Pi-hole which allows you to implement network-wide ad-blocking for all your devices. However, when you’re away from your network (for example on a mobile device or laptop) you won’t get the benefits of this ad-blocking. You also won’t be able to connect to other services running on your network. PiVPN can help with this by allowing you

Read more...

Add Git Information (and more) to Windows Terminal (or PowerShell)

Posted on
5 min read

I’m a fan of Windows Terminal – it makes it easier for me to manage my terminal windows in a tabbed interface and makes it easy to access a terminal for either my Windows machine or the WSL guest in one interface. But sometimes, it is useful to add a bit more context to your terminal window, besides just your current working directory. This additional information might be the current Git branch (or other Git repository details), execution time of commands, system resource usage, or a wid

Read more...

Using Cloudflare Access and tunnels to create an RDP jump host

Posted on
7 min read

Cloudflare Tunnels are a useful way of allowing private services to be accessed remotely, without exposing the devices to inbound connections. This can be combined with Cloudflare Access to provide a secure way of accessing services such as remote desktop. These services can be used to setup a bastion inside a private network. The bastion will then permit a connection to be made to a destination device on the private network. Setting up the Cloudflare Access Application The fi

Read more...

Network-wide Ad Blocking with Pi-hole

Posted on
6 min read

Ads can sometimes be a bit frustrating, or turn up in places we don’t expect. For example, ads on subscription-based services. Serving ads can also consume a substantial amount of bandwidth on some sites. There are a variety of ad blocking browser extensions you can install (such as Adblock Plus or uBlock) on your computer to block ads. However, you have to install these on each device you use, and some devices like TVs and games consoles, don’t support extensions. It would be much

Read more...

Configuring a Vue.js SPA with Environment Variables

Posted on
4 min read

In a previous blog post I showed how to set up ASP.NET Core Web API to support a Vue.js client SPA. In this post I will show how to extend on that example so that the Vue.js SPA supports a development and production configuration. Since I am extending the previous example, I am assuming the API is available at http://localhost:5000 when in development and for this example I will assume that the production API is available at https://example.com. Creating the configuration files

Read more...

Removing Sensitive Information from Git with git-filter-repo

Posted on
4 min read

Git has become the de facto standard in source control. Over 90% of respondents to the 2021 Stack Overflow Developer Survey indicated that they use Git. However, sometimes mistakes can be made and sensitive or secret information accidentally end up in the commit history. Thankfully, tools such as git-filter-repo exist to help rewrite history (the history of a git repository anyway)! In this post, I am going to go through using git-filter-repo to scrub a password or secret from a git repo

Read more...

Supporting Multiple WS-Federation Authentication Schemes in ASP.NET Core

Posted on
5 min read

ASP.NET Core allows you to add support for multiple authentication schemes, such as social auth providers or WS-Federation. This support can be added with or without ASP.NET Identity Core. Users can then use these schemes to authenticate with your web application. While adding support for social authentication providers (such as Twitter and Facebook) is useful, sometimes applications need to support for multiple authentication schemes of the same type. An example of this would be support

Read more...

Install Docker Engine without Docker Desktop on Windows

Posted on
4 min read

Docker have recently announced changes to their pricing and subscriptions which require a paid subscription for users outside of personal, education and small business use. It seems that this license change only applies to Docker Desktop which is the GUI client for Windows and Mac. The good news is that you can install the Docker Engine on Windows using Windows Subsystem for Linux 2! The bad news is that you won’t have easy access to the GUI to manage containers; you’ll have to use the C

Read more...

AI Assistance for Software Developer Productivity – The Good, The Bad & The Ugly

Posted on
5 min read

Software Development can have moments of writing repetitive code. Following the DRY principle can help avoid this, but sometimes one block of code isn’t doing the same thing as another, although it is doing something similar (such as mapping objects in a collection). In these cases AI can be a helpful aid, but it does have drawbacks too! The Good – AI Accelerated Development Artificial Intelligence and Machine Learning have been applied to these kinds of problems for a while, and n

Read more...

Using ngrok with IIS Express and ASP.NET Core

Posted on
3 min read

Sometimes it can be helpful to quickly make the version of a project which is running on your development machine available to others. This could be for webhook integrations, demos, or some other reason. One of the tools you can use to achieve this is ngrok. ngrok creates a secure tunnel and expose the web server running on your machine (usually IIS Express for .NET Projects if you’re working on Windows). As a result, you can give a publicly accessible URL (such as https://a1c2e3g4i5kl.n

Read more...

Microsoft Remote Desktop (RDP) Stuck on "Please Wait"

Posted on
2 min read

I often use Remote Desktop Connection (RDP) to connect to computers remotely when I am out and about. However, recently when I tried to remotely connect using RDP, I became stuck at a blue screen with a “Please Wait” message after connecting. After a few minutes of waiting, I became a bit suspicious that something wasn’t working correctly, especially since I was using the connection just fine a few hours before. Below are some of the solutions I’ve found that may work if you find yo

Read more...

Logging in .NET Core using ILogger

Posted on
4 min read

Logging is an important part of software development. It helps us know that tasks have been completed, monitor applications and provides a trail to follow when things don’t work. Microsoft has included a logging framework in .NET Core and ASP.NET Core to allow developers to easily implement logging and choose their own logging provider (this is the part which decides how to store your log messages). A good logging solution can be invaluable when an application stops working as expec

Read more...

Using a Vue.js SPA with ASP.NET Core Web API

Posted on
9 min read

I recently started working on a new side project and decided to implement it as a single page application (SPA). For this, I chose to build an API powered by an ASP.NET Core Web API and a Vue.js powered front-end to consume the API. I could find templates included in Visual Studio for AngularJS and React but nothing for Vue.js. Since I already have experience with Vue.js I decided to document the steps I used to create my starter project from a blank ASP.NET Core web app using ASP.NET Co

Read more...

Handling null values in C#

Posted on
4 min read

Handling null values in C# and .NET comes with the territory. Null values were introduced by Tony Hoare in mid-1960s to represent missing or unknown data. This is a useful capability but it has resulted in null reference exceptions becoming one of the most common causes of bugs which developers face. As a result, Tony Hoare now calls the null reference the ‘billion dollar mistake’. C# has always allowed reference types to be nullable, and as a result, the NullReferenceException is someth

Read more...

What makes a good log message?

Posted on
5 min read

Logging can provide important information about the behaviour of software applications. It allows operations staff to monitor application performance and gives developers a trail to follow when trying to diagnose the cause of errors. With this in mind, it is worth considering what is good information to record in a log file and what format it should be recorded in. Below is a list of the general guidelines I follow when writing log messages. Use log levels to indicate severity

Read more...

How to send emails in .NET Core with MimeKit and Mailkit

Posted on
3 min read

The ability for an application to send emails is a very common requirement. This can be for emails such as providing account information, sending marketing emails or even a password reset email. This post will cover how to send an email using MimeKit and MailKit from an ASP.NET Core MVC web application. I will use MailSlurper as a local SMTP server to test the sending of the emails. You can use any SMTP server you prefer though. Creating the ASP.NET Core MVC demo project

Read more...

Changing Query String values in ASP.NET MVC

Posted on
2 min read

Recently I was trying to update a query string by adding or updating a parameter for URLs generated in a partial view. I found an excellent example for achieving this by setting route data here however this didn’t preserve current query string values in the URL. I’ve extended upon that code and updated it to include the query string values in the route data which will be appended to the query string in the generated URL (assuming the parameter key doesn’t match part of the route). p

Read more...

Disabling an ASP.NET MVC input control

Posted on
2 min read

I love ASP.NET MVC. It is a great framework to get web apps quickly built. However using the built in HtmlHelper methods on your views isn’t without its issues. An example of this is when trying to disable a HTML input control which has been built using HtmlHelper. You can add the “disabled” attribute which would be required by making use of one of the helper’s overloads however if you want to conditionally disable a control (based on your view model) it can result in your view’s code be

Read more...

Fixed/Sticky Headers on ASP.NET GridView using jQuery

Posted on
2 min read

The GridView control in ASP.NET Web Forms is an extremely useful and quick way of getting data out to the user in a nice tabular format. It does have one weak spot though and that is some of the tags it uses when doing this. Specifically, not putting the header information inside a <thead> tag. So why is this important? When you have a LOT of rows (as some do) after you’ve scrolled down the page and the table headers are out of view you can forget which column is which, especially i

Read more...

Sending e-mails through Office 365

Posted on
5 min read

I recently signed up for an Office 365 Business Essentials subscription to get the benefit of Exchange and other nice features without the hassle of managing it myself, as part of this I wanted to setup a no-reply e-mail address I could use to send automated e-mails without having to fork out extra for another user. The answer I found lies in using a shared mailbox for the e-mail address and preventing it from accepting incoming e-mails, then configuring the client to use Office 365 as an SMT

Read more...

Strongly Typed Data in ASP .NET Web Forms

Posted on
3 min read

In ASP .NET Web Forms you’ve previously had to use strings to specify which properties you’d like to output when databinding, which would probably end up looking something like the following. <asp:templatefield headertext="Last Name"> <itemtemplate> <asp:literal runat="server" text="<%#: Eval("LastName") %>"> </asp:literal></itemtemplate> </asp:templatefield> In all likelihood it could probably look far less tidy if you’ve ever needed to do any formatting on values y

Read more...

Install WPScan on Ubuntu 13.10

Posted on
2 min read

Prerequisites Since Ubuntu 13.10 doesn’t come set up for development work out of the box there are a few things you need to download and install first. Thankfully this is made easy by apt-get by just running the following command to get everything ready. sudo apt-get install libcurl4-gnutls-dev libopenssl-ruby libxml2 libxml2-dev libxslt1-dev ruby-dev build-essential git Setting up WPScan First off we need to clone the git repository to get the code for WPScan. We can do

Read more...

Send E-mail through Microsoft Exchange using .NET

Posted on
2 min read

Recently I needed to send an e-mail using Microsoft Exchange Server from an ASP .NET Web App. My first attempt involved using the classes in the System.Net.Mail namespace however I quickly realised this wasn’t the way to be going about it as I had very little luck getting a connection to the server. After a while spent with Google I realised that there were some web services which could be used to perform tasks, these were called Exchange Web Services (EWS) and thankfully Microsoft provide a m

Read more...

Using a RequiredFieldValidator on a DropDownList in ASP .NET

Posted on
2 min read

In most applications today drop-down lists default to a “Please select..” option with some form of validation to ensure the user makes their own selection. In ASP .NET web forms this frequently results in a drop-down list being created using code similar to that displayed below. <asp:DropDownList ID="ddlOptions" AppendDataBoundItems="true" runat="server"> <asp:ListItem Text="Please select an option..." Value="-1" /> </asp:DropDownList> We can add an ASP .NET RequiredFie

Read more...

Boot Camp Support Software

Posted on
1 min read

After upgrading a Boot Camp Windows 7 installation to Windows 8 I found that the Boot Camp drivers needed to be updating to regain control of the function keys and built-in camera. The Boot Camp software is available at Apple Boot Camp Support Website. After the download I found the installer failed to run with the error “The installer encountered errors before Boot Camp could be configured“. It turns of some programs interfere with the Boot Camp installer, especially ones rela

Read more...

How to allow HTML content in ASP .NET MVC

Posted on
1 min read

Sometimes in web development, you need to provide an easy-to-use editor for non-technical users to input or change content where extra styling is required such as making text bold or italic. However unless you use (or code yourself) an editor which uses some form of BBCode you’re going to come across the following error message if you’re using ASP .NET. I have seen various “fixes” to this suggested, the most frequent being turning off request validation entirely. While this will

Read more...

ASP .NET AJAX Control Toolkit Reorder List control and LINQ

Posted on
2 min read

The ASP .NET AJAX Toolkit is quite a useful and yet under-used set of controls. However they can also quickly lead to bizarre issues and worse performance than normal if they are not properly understood or used correctly. This issue is compounded when you take into consideration that quite a few of the controls included have a number of fairly unique bugs in them. An instance of this is in the Reorder List control which is intended to allow a user to re-order a list of items by simple dr

Read more...