In today's post, you will learn how to create a PowerShell script to enable proxy forwarding using Application Request Routing cache (ARR). If you are a regular reader of this website, you will know that I recommend investing the time and energy to automate your development and deployment process on every project. On a recent project, we wanted the ability to set up a server completely from scratch, and then deploy that website 100% automatically.
As the website was a legacy project, we also needed to use ARR to act as a reverse proxy in order to get assets out of an even older legacy website. To set the scene, the site used three virtual machines in a staging/live CMS configuration, GIT for source control and Octopus deploy to deploy the code. As part of this process, we needed to automatically install the ARR module. Whenever I'm messing around with build scripts I use chocolately to automate installing any third-party modules/applications on a server.
To enable the ARR proxy feature after it has been installed via chocolately, creates a dilemma. Some of the XML required to set the proxy up will not have been run yet, as IIS won't have on tear up. Specifically, the Proxy section group section will not have been created. This means that my script ended up being a little bit more complex than I planned.
The Application Request Routing Powershell Script
Let us now look at my almighty script 💁👌🎍😍
Lets us walk through the script. First, I needed to create the section group, then save it, then reload the app into memory in order to write to the proxy section. This 100% confused me for a few hours, so be warned! There are probably other ways of manipulating the applicationhost config
in PowerShell. I went for Microsoft.Web.Administration as that's sort of its purpose. using the admin manager allowed me to update and save my IIS configuration. Magic! With this script, I could get ARR working on a blank virtual machine on tear up, beautiful. Happy Coding 🤘