Skip to content
/

When I start on a project that uses Azure resources, one of the first things I do is build the infrastructure and automate the deployment using VSTS or TFS.
In this post I‘ll explain how you can extend Azure Web Apps with Virtual Applications and Virtual Directories using ARM templates.

When I start on a project that uses Azure resources, one of the first things I do is build the infrastructure and automate the deployment using VSTS or TFS. The definition of the infrastructure is defined using ARM templates.
When you search online you will find plenty of examples on how to create and use ARM templates. But when you move beyond the basics you’ll find out the documentation is lacking.

In this post, I’ll explain how you can extend Azure Web Apps with Virtual Applications and Virtual Directories using ARM templates.

I won’t be covering on reasons why you would want to use Virtual Applications or Directories. If you’re interested in more background on these, you can read .

At the end of the post you will find the link to the source code.

The Web App definition

We start with a basic site template, for brevity I skipped the app service definition.
The resources property is an empty collection by default.

{
  "type": "Microsoft.Web/sites",
  "kind": "app",
  "name": "LoremIpsumWebApp",
  "apiVersion": "2015-08-01",
  "location": "[resourceGroup().location]",
  "resources": [],
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', 'LoremIpsumAppService')]"
  ]
}

Adding the Configuration resource

Configuration of the Web App properties is done with a resource with the type of Microsoft.Web/sites/config.

The name of the resource starts with the name of the parent Web App extended with /web.

In the property properties, you can configure several configuration properties like Virtual Applications, enabling Always On or disabling PHP.

A Web App always contains a root application.

{
  "type": "Microsoft.Web/sites/config",
  "name": "LoremIpsumWebApp/web",
  "apiVersion": "2015-08-01",
  "dependsOn": [
    "[resourceId('Microsoft.Web/sites', 'LoremIpsumWebApp')]"
  ],
  "properties": {
    "phpVersion": "",
    "alwaysOn": "true",
    "virtualApplications": [
      {
        "virtualPath": "/",
        "physicalPath": "site\\wwwroot",
        "virtualDirectories": null
      }
    ]
  }
}

We add the new config resource as a child resource to the Web App:

{
  "type": "Microsoft.Web/sites",
  ...
  "resources": [
    {
      "type": "Microsoft.Web/sites/config",
      ...
    }
  ],
  ...
}

Other properties trimmed for brevity.

Adding Virtual Applications

We can add a Virtual Application by adding it to the virtualApplications array.
There are 2 required properties:

  • The virtualPath is the relative path to the root URL of the website.
  • The physicalPath is the (relative) path on disk where the files for this application are stored.
{
  "virtualPath": "/DolorSitAmet",
  "physicalPath": "site\\dolor-sit-amet",
  "virtualDirectories": null
}

Adding Virtual Directories

Virtual Directories are always a part of a Virtual Application.

A Virtual Directory has the same two required properties that are needed for a Virtual Application: virtualPath and physicalPath.

{
  "virtualPath": "/Images",
  "physicalPath": "site\\path-to\\images"
}

This object is added to the Virtual Application:

{
  "virtualPath": "/DolorSitAmet",
  "physicalPath": "site\\dolor-sit-amet",
  "virtualDirectories": [
    {
      "virtualPath": "/Images",
      "physicalPath": "site\\path-to\\images"
    }
  ]
}

Now you can deploy the ARM template to your Azure Resource Group and then configure a Web Deploy to your brand new Virtual Application!

Source code

I’ve create a GitHub Gist with the a full working deployment template sample for reference.

Filed under Azure
Last update:
/

The other day I needed to get the URLs for all pages in my blog for some PowerShell scripting I wanted to do. Like most websites this blog has a sitemap and I wanted to use that as a source.
As I couldn’t find any existing PowerShell scripts on the web that I could use, I just wrote one myself.
Now I like to share this script with you.

The other day I needed to get the URLs for all pages in my blog for some PowerShell scripting I wanted to do. Like most websites this blog has a sitemap and I wanted to use that as a source.
As I couldn’t find any existing PowerShell scripts on the web that I could use, I just wrote one myself.
Now I like to share this script with you.

At the end of the post you will find the link to the source code.

Basic usage

Just execute the script with an URL to an XML Sitemap.

.\ConvertFrom-SiteMap.ps1 -Url https://blog.hompus.nl/sitemap.xml

Which results in something like this:

loc        : https://blog.hompus.nl/
lastmod    : 2017-02-10T23:57:52+00:00
changefreq : daily
priority   : 1.0

loc        : https://blog.hompus.nl/category/azure/
lastmod    : 2017-02-08T17:43:41+00:00
changefreq : weekly
priority   : 0.3

loc        : https://blog.hompus.nl/category/csharp/
lastmod    : 2016-12-14T08:53:46+00:00
changefreq : weekly
priority   : 0.3

Displaying only the first 3 entries

Under the section XML tag definitions the protocol states that the lastmod, changefreq and priority attributes are optional, so they can be missing when querying a different sitemap.

Now you can do basic PowerShell manipulation of the result set like sorting, selecting, filtering and formatting. For example:

.\ConvertFrom-SiteMap.ps1 -Url https://blog.hompus.nl/sitemap.xml 
                                   | Sort-Object priority -Descending 
                                   | Select-Object priority, changefreq, loc -First 5 
                                   | Where-Object { $_.priority -ge 0.3 }
                                   | Format-Table

Outputs:

priority changefreq loc
-------- ---------- ---
1.0      daily      https://blog.hompus.nl/
0.6      weekly     https://blog.hompus.nl/about/
0.6      weekly     https://blog.hompus.nl/archives/
0.3      weekly     https://blog.hompus.nl/category/windows/
0.3      weekly     https://blog.hompus.nl/category/visual-studio/

Ignoring Sitemap Index entries

An sitemap can also be a Sitemap Index File. The file then contains links to other sitemap files.
By default the script will follow these links. If you don’t want this to happen you can set the NoFollow switch.

.\ConvertFrom-SiteMap.ps1 -Url https://blog.hompus.nl/sitemap.xml -NoFollow

Source code

The complete source code is available as a GitHub Gist: ConvertFrom-SiteMap.ps1.

/

Last month I gave my session, in Dutch, titled Serious Request, Azure als schaalbaar platform during the dotNed Saturday event.
I’m sharing my slides so you can start building awesome, secure, scalable, performing and monitorable web platforms using Azure.

Last month I gave my session, in Dutch, titled Serious Request, Azure als schaalbaar platform during the event.
First I’d like to thank everyone attending this session.

The session was about my experiences using Microsoft Azure to build a high available, secure and scalable platform for digital donations.
This platform is used during 3FM Serious Request, the annual charity event organized by the Dutch radio station 3FM for the Dutch Red Cross.

I’m sharing my slides so you can use my guides, tips & tricks to start building awesome, secure, scalable, performing and monitorable web platforms using Azure.

Any questions about my session? Just contact me.

Filed under Azure
Last update: