Azure

Migrating your applications to Azure using Virtual Machine Scale Sets, Packer and Virtual Machine extensions – Part 1

So you are ready to move your application to Azure but it is not fully optimized for the cloud. You looked into App Services (web apps), but to be able to really get the best of them, it would need some definitive improvements in the code. You go back to your team and management and propose them a lift and shift that would make everyone happy. You then plan your improvements in your timeline and estimates. How can you effectively lift and shift your application so that it can be highly available (within one region) and scalable? In this series of posts, I will show you how you can package your application in an image and have it ready for…

Read more
C#

Getting feedback from EntityFramework Core through diagnostics

Have you ever wanted to get some diagnostics information about Entity Framework Core when it comes to the actions it’s doing such as when a command is executing or executed, when it’s opening a connection to the database or even when there’s an error, to name just a few? I was searching for a way to be able to get the duration of the query it was executing. I was glad to find out that Entity Framework Core hooks itself into DiagnosticSource, a simple module that allows code to be instrumented for production-time logging of rich data payloads for consumption within the process that was instrumented.1 Getting hooked into the diagnostic pipeline DiagnosticSource uses the observer pattern to notify its observers. If you…

Read more
Azure, PowerShell

SSL certificates management using Lets Encrypt, Azure Automation and Web Apps

I’ve been doing a lot of automation lately in regards to SSL certificates and Lets Encrypt. As you know, and I’m sure you are the same, I do not like redoing stuff over and over when I can just automate the process. Azure Az PowerShell modules gives us a lot of flexibility for that and I like to take advantage of it. In this post, I would like to guide you on how you can achieve Automating the generation of Lets Encrypt certificate to your Key Vault using Azure Automation Updating the certificate on your App services so that you can rebind it to your Web Apps Automation of generation of Lets Encrypt certificate(s) Lets Encrypt has a way of…

Read more
Azure, PowerShell

Finding the SKUs of Azure VMs images with Powershell

I always struggle to know what to put in the imageReference node of the storageProfile node for an Azure VM when I want to automate the creation process through ARM (Azure Resource Manager) templates. We can find all of those using the Azure PowerShell modules. Below is a small script to automate the creation of the imageReference node where you can find and filter through the different location, publishers, offers and skus to get what you need.

Happy ARMing!

Read more
C#, Docker

Running an ASP.NET Core application targeting .NET Framework in Docker

Recently, I’ve came across an interesting challenge that was to dockerize an ASP.NET Core 2.2 application targeting .NET Framework 4.7.2. The reason this application was targeting .NET Framework was because it was using a library that unfortunately had no plans to move to the .NET Core platform. That library was a port from Java. As such I had to take a decision: rewrite the whole application in Java to support this library more natively, or try to find an alternative library that did the same thing. Sometimes it’s better to sleep on such decision. Well it paid off. I had forgotten that possibly I could use mono to run it. I took this as a challenge and used one of…

Read more
Azure

End to End SSL solution using Web Apps and Azure Application Gateway multisite hosting

High performance and security (amongst other things) are the 2 non-functional requirements that usually first come to mind when we design an infrastructure architecture for the applications we develop. The usual 2 concepts that pop up with these 2 requirements are load balancing and firewalls. How can you easily achieve and check these 2 concepts when you are developing your architecture in Azure? One component that you can use for this is the Azure Application Gateway. Azure Application Gateway is a web traffic load balancer (OSI layer 7 load balancer) that enables you to manage traffic to your web applications. Some of its features include (but not limited to): URL-based routing: make routing decisions based on additional attributes of an…

Read more
Azure, Docker

Connecting to Azure Redis Cache with Docker

If you are a Windows user and you want to access your Redis cache, you probably have realized that getting the redis-cli for Windows is not as easy as 1,2,3. You probably also wandered around the internet trying to find a free GUI that does the job of access Redis in a secure way (that is that is supports SSL/TLS out of the box). You then realized again that they probably have limitations themselves and it’s also not easy as 1,2,3. Your last solution, use the redis-cli that comes with the redis server on a linux flavored distro. Lucky for you, in Windows 10, you can install the Linux subsystem and then install redis which includes the redis-cli. Great, but…

Read more
Azure, C#

Loading a X509 certificate from Azure KeyVault into a .NET Core application

In a context where we are now using APIs a lot more than we used to, it becomes important to secure them. One way we can secure them is using the OAUTH/OpenId protocol, which relies on Json Web Tokens (JWTs).  A JWT needs to be generated and digitally signed by the authority (what we call a Security Token Service (STS)) your APIs trust. They require signed JWTs to prevent attackers from altering or counterfeiting such tokens in an attempt to gain unauthorized access to the resources secured by the APIs. A good open source implementation of such authority is IdentityServer4 which also gives you a lot more features than just being a STS. In development mode, IdentityServer4 provides you with…

Read more
Azure, Database, Web

Using managed identities with SQL Azure Database in ASP.NET Core

We are now in a world where we want to eliminate passwords as much as possible, and Microsoft, through its cloud platform Azure, is trying to help us do that. Today, I want to show you how you can secure your SQL Azure database using managed identities so you don’t have to create any SQL Login and carry passwords around. Prerequisites To demonstrate this, I will be using the following Azure resources: Azure App Service Plan / App Service Azure SQL Server 1 Azure SQL Database Make sure you have those already created. You also will need either the Azure CLI or Azure Az powershell module. In my case, I will be using the Azure Az powershell module. Moreover, in…

Read more
Azure

Remove a directory from your Azure account

My account had a directory in Azure that I was not a member of anymore and that I wanted to remove.  You may be in a similar situation in that you have a directory in your Azure account that you don’t need anymore and you want to remove it from your account. It is now possible to self-leave a directory as show in this post. Here is the accepted answer: 1. Log into the Access Panel at https://myapps.microsoft.com In the upper-right corner, select your name. 2. Next to Organizations, select the settings icon (gear). Note: If you can’t see the settings icon (gear), widen the browser screen. The Access Panel user interface is a reactive interface that adepts to the…

Read more
Continuous Integration, DevOps

Using WebDeploy in a CI/CD pipeline with powershell

It’s cool to play around with new Tech and new stuff but sometimes you have to come back to the basics that have been working for years. I’ve been setting up the CI/CD pipeline at my work place for my team and one task consisted of deploying the generated code documentation with DocFX, to our development web server hosted through IIS. Since I had custom logic I wanted to execute, I couldn’t use the built in WebDeploy task that was provided to me. So when you are doing DevOps, PowerShell becomes your best friend. For those who are struggling to install WebDeploy in IIS (8+), follow the guide Inigo Montoya put together. You should also configure a site using a Non-Administrative user…

Read more
C#, WebApi

Testing SignalR in ASP.NET Core with Integration Tests

As promised in my last post, I’m following up on how to test your SignalR hubs in an end to end manner using TestServer. This post is a build up on my last post so if you haven’t read it, go do so now! Setup I have a Hub named ChatHub that has the following method:

My clients all are connected to (listen to) a method to receive messages called  OnMessageReceived. Tests In my test class, I created a method to help me start my connection. If you plan on testing multiple hubs, you may want to move this method to a helper class.

Dom, my Hubs are protected with a Jwt Token… No worries, you can pass your…

Read more
C#, WebApi

Testing a WebAPI in .NET Core with Integration tests

NOTE: This posts targets ASP.NET Core 2.X. If you are looking for ASP.NET Core 3.1, see my repository. I’ve also made a NuGet package for easier consumption. You finished developing your API, and you are ready and eager to push it to production. You then realize that you are missing some tests to make it a real production ready API. Lucky for you, ASP.NET Core 2.X provides us with an In-Memory HTTP Server (TestServer) to help us achieve this. This post aims to help you write end to end tests (e2e) using ASP.NET Core 2.1 (and possibly future versions!) in order to test the flow of your API. Remember that having tests in place, whether they are unit or end to end,…

Read more
Azure, C#, Web

Connecting Azure AD and Azure AD B2C to IdentityServer4

I’ve been playing with IdentityServer4 lately and I wanted to share you guys the findings I’m finding while I am playing with it. IdentityServer4 for the ones who don’t know it, is an OpenID Connect and OAuth 2.0 framework for ASP.NET Core 2. You can read all about it here. In today’s post, I would like to show you how you can connect Azure AD and Azure AD B2C to IdentityServer4 as external providers. When doing so, IdentityServer becomes a federated gateway. Both implementation are similar, however, Azure AD and Azure AD B2C have specificities that are particular to them. Connecting to Azure AD We can connect Azure AD to IdentityServer through an external OpenIdConnect provider. To do that, you…

Read more
Azure, C#, Visual Studio

The moment I came to play with .NET Standard 2.0 – Azure Functions

A lot has changed ever since I played with Azure Functions and .NET Standard 2.0. If you remember from my previous post, I was talking about how you had to set the FUNCTIONS_EXTENSION_VERSION to beta in order to benefit from the new runtime. I also talked about how I had a problem with the connection manager to access the app settings. Well the good news is that the team now fully migrated to the new Configuration modeling from ASP.NET core. You can now easily refer to your configurations by importing the following packages and using the following code to have access to your configuration: Nuget package Description Microsoft.Extensions.Logging Main logging package Microsoft.Extensions.Logging.Abstractions Makes SetBasePath() available Microsoft.Extensions.Logging.Json Makes AddJsonFile() method available…

Read more