In today's post, I'm going to explain how you can use powershell script to enable proxy forwarding using Application Request Routing cache (ARR). If you are a regular reader of this website, then 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, deploy the website 100% automatically.

As the website was a legacy project, we also needed to use ARRto act as a reverse proxy, to get assets out of an even older legacy website. To set the scene, we use 3 VM's in a staging/live CMS configuration, GIT for source control and Octopus 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 dilema.  Some of the XML required to set the proxy hasn't been run yet, as IIS hasn't been run, specifically, the Proxy section group and section isn't created.  This means my script ended up being a little bit more complex than I planned.

The Application Request Routing Powershell Script

Some interesting things to note: I needed to create the section group first, save it, then reload it 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', but I went for Microsoft.Web.Administration as that's sort of it's purpose.