.NET Core templates for Azure Web App

David Bottiau
3 min readJun 8, 2020

With the emergence of .NET Core and more importantly of its amazing dotnet cli, there are a number of templates you can use like the default ones: ASP.NET Empty project, ASP.NET Web API, ASP.NET with React/Angular/etc… They really help us to get started in a very short time.

But there is still one thing that bothers me is that I found no template that gives you the possibility to start an ASP.NET application using Azure services. And so the objective is to describe the following project: ASP.NET Core Azure Templates.

Humble and clean template

ASP.NET Core Azure Templates is a list of templates used to generate ASP.NET Core web apps using ready-to-use Azure features:

  • Healthchecks
  • SignalR
  • Azure SignalR
  • Azure Active Directory
  • Microsoft Graph API (using Azure AD)
  • Azure Application Insights

Healthchecks

By using Healthchecks, we provide a way to verify the health of the web app.

The healthchecks configuration will provide the minimum of probes for the different features used in the app: Microsoft’s Azure AD endpoint, Microsoft Graph endpoint and the self SignalR hub created by default.

The package also provides a UI for these probes, which looks like something like this:

Xabaril Healthchecks UI

SignalR + Azure SignalR

SignalR is provided by default in the template, with a default Hub. And you also have the nice addition of Azure SignalR. For dev/testing purpose, the Azure SignalR service is no enabled in Development environment.

Notice that the Azure:SignalR:ConnectionString is not provided in the appsettings.json file by default (see below). It is because this information is generally provided during deployment in the connection strings of the Azure App Service.

Azure Active Directory

The Azure Active Directory authentication is integrated by default, for both HTTP and SignalR requests.

Microsoft Graph API (using Azure AD)

The Microsoft Graph API can be nice addition to an Azure AD related web app. The Microsoft Graph API will allow to fetch additional informations about the current user authenticated. It can be really useful in certain scenario.

The MS Graph authentication is automatically made on top of the Azure AD authentication. There is also a default GraphApiService which provides some basic features. You can obviously extend it to dig deeper in the MS Graph API.

Azure Application Insights

By using Azure Application Insights, the app will send every logs and metrics to ensures the app is working well.

Additional features

These features are not related to Azure but they are also integrated by default in the templates:

  • Dependency Injection (using the native service collection: Singleton/Scoped/Transient)
  • Default authorizations/permissions (Reader and Writer roles)
  • Swagger + Swagger UI

How to use?

With dotnet cli, it is pretty easy to get started, see:

  1. Install the template package

dotnet new -i AspNetCoreAzureTemplates

2. Create a new project called MyWebApp

mkdir MyWebApp
cd MyWebApp
dotnet new azurewebapp

It will then automagically creates the Visual Studio solution and the architecture following the name of your folder.

3. Configure the appsettings.json

You will have some unfilled properties in the json configuration of the app. You will simply need to fill them with the configuration of your project. Here is the goal of each property:

  • <INSTRUMENTATION_KEY> — instrumentation key provided to send data to an App Insights instance
  • <TENANT> — Tenant of the Azure AD app
  • <CLIENT_ID> — Client Id of the Azure AD app
  • <CLIENT_SECRET> — Client secret of the Azure AD app, solely used to be able to call the Microsoft Graph API on behalf of the Azure AD app

4. Enjoy!

Build your own solution by adding new features and overriding some of the existing ones if necessary.

Next steps

There are so many services provided by Azure that it’s hard to follow. Hopefully, we target the most requested features in a .NET Core app hosted on Azure. If you see missing features, do not hesitate to give feedback.

If you are willing to suggest an idea of if you want to contribute in any way, you can find the source code for the templates here:

--

--

David Bottiau

Software designer, open-minded, Lean being and UX advocate.