<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>C# on Jan-V.nl</title><link>https://jan-v.nl/tags/c%23/</link><description>Recent content in C# on Jan-V.nl</description><generator>Hugo</generator><language>en-us</language><copyright>© 2006-2026 Jan-V.nl All Rights Reserved.</copyright><lastBuildDate>Tue, 01 Jun 2021 08:00:00 +0200</lastBuildDate><atom:link href="https://jan-v.nl/tags/c%23/index.xml" rel="self" type="application/rss+xml"/><item><title>Using Key Vault references with Azure App Configuration</title><link>https://jan-v.nl/post/2021/using-key-vault-with-azure-app-configuration/</link><pubDate>Tue, 01 Jun 2021 08:00:00 +0200</pubDate><guid>https://jan-v.nl/post/2021/using-key-vault-with-azure-app-configuration/</guid><description>&lt;p&gt;When working in Azure, storing secrets in &lt;a href="https://docs.microsoft.com/en-us/azure/key-vault/general/?WT.mc_id=AZ-MVP-5003246"&gt;Key Vault&lt;/a&gt; is a good idea. And to make it better, there&amp;rsquo;s the Key Vault Reference notation. This feature makes sure no one can read the secret(s) unless someone grants permission.&lt;br&gt;
For storing configuration, values a different service is available, called &lt;a href="https://docs.microsoft.com/en-us/azure/azure-app-configuration/?WT.mc_id=AZ-MVP-5003246"&gt;Azure App Configuration.&lt;/a&gt;&lt;br&gt;
Both services are excellent for storing &amp;amp; sharing the values of your cloud services.&lt;/p&gt;
&lt;p&gt;Wouldn&amp;rsquo;t it be great to be able to combine the two? What I mean by that is to use Key Vault references inside your App Configuration. Well, you can!&lt;br&gt;
There is some work involved as you need to set up access to Key Vault from within the application.&lt;/p&gt;
&lt;h1 id="key-vault-references-in-app-configuration"&gt;Key Vault References in App Configuration&lt;/h1&gt;
&lt;p&gt;If you&amp;rsquo;re using the Azure Portal, it&amp;rsquo;s easy to add a new Key Vault reference in the App Configuration.&lt;br&gt;
Head to the Configuration Explorer and press the Create button.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jan-v.nl/images/pre/2021-add-key-vault-reference-in-app-configuration.png" alt="Add key vault reference in App Configuration"&gt;&lt;/p&gt;
&lt;p&gt;It will bring a small blade to the side of the screen from which you can add the secret with an appropriate name.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jan-v.nl/images/pre/2021-create-key-vault-reference-in-app-configuration.png" alt="Create key vault reference in App Configuration"&gt;&lt;/p&gt;
&lt;p&gt;Having finished this, press the Apply button, and you&amp;rsquo;ll see the reference added and visible in the Configuration Manager.&lt;/p&gt;</description></item><item><title>Using an Azure Managed Identity to authenticate on a different App Service</title><link>https://jan-v.nl/post/using-an-azure-managed-identity-to-authenticate-on-a-different-app-service/</link><pubDate>Wed, 25 Dec 2019 07:00:00 +0200</pubDate><guid>https://jan-v.nl/post/using-an-azure-managed-identity-to-authenticate-on-a-different-app-service/</guid><description>&lt;p&gt;A couple of weeks ago, I was tasked to implement authentication between the services we have in our Azure landscape. I knew this can be done by using the Managed Identity, as we were doing this on a project I was involved with in the past.&lt;/p&gt;
&lt;p&gt;However, I had never actually done this myself. Most of the time the System Administrators were configuring everything and I just had to copy-paste some Guids in a configuration file. After doing some digging into the matter, it was a bit harder to set this up as I had expected at the start.&lt;/p&gt;
&lt;p&gt;Lucky for me, &lt;a href="https://joonasw.net/"&gt;Joonas Westlin&lt;/a&gt; has some excellent posts on the matter which have helped me enormously. He was also able to help me out on &lt;a href="https://stackoverflow.com/a/58996722/352640"&gt;Stack Overflow when I was stuck&lt;/a&gt; and couldn&amp;rsquo;t find out why the authentication wasn&amp;rsquo;t working correctly.&lt;/p&gt;
&lt;p&gt;Much of what I&amp;rsquo;ll be writing down here will be similar to Joonas his posts on the matter. I&amp;rsquo;ll be using some different wording.&lt;br&gt;
The posts I&amp;rsquo;ve used to learn this stuff were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://joonasw.net/view/azure-ad-authentication-aspnet-core-api-part-1"&gt;Azure AD Authentication in ASP.NET Core APIs part 1&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://joonasw.net/view/calling-your-apis-with-aad-msi-using-app-permissions"&gt;Calling your APIs with Azure AD Managed Service Identity using application permissions&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://joonasw.net/view/defining-permissions-and-roles-in-aad"&gt;Defining permission scopes and roles offered by an app in Azure AD&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Getting the group claims when authenticating with Azure Active Directory</title><link>https://jan-v.nl/post/getting-the-group-claims-when-authenticating-with-azure-active-directory/</link><pubDate>Wed, 27 Nov 2019 08:13:00 +0200</pubDate><guid>https://jan-v.nl/post/getting-the-group-claims-when-authenticating-with-azure-active-directory/</guid><description>&lt;p&gt;I started working on some internal web applications for a customer. For these types of applications, it makes a lot of sense to use Azure Active Directory to authenticate users and use their AAD groups/roles to authorize them on specific pages.&lt;/p&gt;
&lt;p&gt;I wanted to authorize users by the AAD groups they are placed in. Some users can access Production data, while others are only allowed to access data from the Test environment, all based on the groups they are in. Because this is already configured by our system administrators, I want to use these groups for my application(s) also.&lt;/p&gt;
&lt;p&gt;This sounds easy enough, and it is, but you have to do some manual work in Azure Active Directory to make this possible. It took me too much time for my liking, so I hope this post helps others (and myself) in the future.&lt;/p&gt;
&lt;p&gt;One of the first things you need to do is create a new App Registration in the AAD and give it permission to &lt;code&gt;User.Read.All&lt;/code&gt; to read the users&amp;rsquo; claims.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jan-v.nl/files/ded07d21-9848-4262-a850-d837af2c2e81.png" alt="image"&gt;&lt;/p&gt;
&lt;p&gt;This requires consent from your Administrator, so make sure they are available or you have enough permissions yourself to do this.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jan-v.nl/files/8d22eb70-7e9a-41b6-a732-543c87cca49f.png" alt="image"&gt;&lt;/p&gt;
&lt;p&gt;When this is set up correctly, head to the &lt;code&gt;Manifest&lt;/code&gt; blade.&lt;/p&gt;</description></item><item><title>Authentication of Microsoft Teams MessageCards actions in your API</title><link>https://jan-v.nl/post/authentication-of-microsoft-teams-messagecards-actions-in-your-api/</link><pubDate>Wed, 26 Jun 2019 06:00:00 +0200</pubDate><guid>https://jan-v.nl/post/authentication-of-microsoft-teams-messagecards-actions-in-your-api/</guid><description>&lt;p&gt;Being able to create Message Cards or Actionable Messages in Microsoft Teams &lt;a href="https://jan-v.nl/post/devops-easier-with-logic-apps-and-teams"&gt;via a Logic App&lt;/a&gt; or &lt;a href="https://jan-v.nl/post/doing-your-devops-stuff-with-azure-functions-instead-of-logic-apps"&gt;an Azure Function&lt;/a&gt; is great. Especially if you can use this to invoke logic on &lt;a href="https://jan-v.nl/post/update-your-microsoft-teams-notifications-via-an-azure-function"&gt;your API and update the message in the Teams channel&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;However, you don&amp;rsquo;t want everyone to invoke a management API endpoint you&amp;rsquo;ve exposed to &amp;lsquo;do stuff&amp;rsquo; in your cloud environment. Normally, you&amp;rsquo;d want to authenticate if the user pressing the button (read: invoking the endpoint).&lt;/p&gt;
&lt;p&gt;Lucky for us, this is very doable when invoking the endpoint via a Teams MessageCard/Actionable Message.&lt;/p&gt;
&lt;h1 id="the-token"&gt;The token&lt;/h1&gt;
&lt;p&gt;Because Microsoft Teams is part of the Office 365 suite, you will be logged in as a user on the tenant. Therefore, the software has a user context and is able to pass this along to your API via a &lt;a href="https://oauth.net/2/bearer-tokens/"&gt;JWT Bearer token&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you log in to the web client of Microsoft Teams (&lt;a href="https://teams.microsoft.com"&gt;https://teams.microsoft.com&lt;/a&gt;) with your favorite browser you&amp;rsquo;ll be able to find the token which belongs to you.&lt;/p&gt;
&lt;p&gt;In order to test this, I&amp;rsquo;ve created a new MessageCard in my Teams channel with 1 &lt;code&gt;potentialAction&lt;/code&gt; which will invoke an Azure Function.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jan-v.nl/files/ea1154f8-abdb-4028-826e-dacb33c11eee.png" alt="messagecard with AuthorizationTest button"&gt;&lt;/p&gt;
&lt;p&gt;If you open up the network tab of your browser&amp;rsquo;s Developer Tools and press the &lt;em&gt;AuthorizationTest&lt;/em&gt; button you&amp;rsquo;ll see the request is made to a Teams endpoint called &lt;code&gt;executeAction&lt;/code&gt; with a bearer token in the &lt;code&gt;Authorization&lt;/code&gt; header.&lt;/p&gt;</description></item><item><title>Update your Microsoft Teams notifications via an Azure Function</title><link>https://jan-v.nl/post/update-your-microsoft-teams-notifications-via-an-azure-function/</link><pubDate>Wed, 12 Jun 2019 06:00:00 +0200</pubDate><guid>https://jan-v.nl/post/update-your-microsoft-teams-notifications-via-an-azure-function/</guid><description>&lt;p&gt;In my &lt;a href="https://jan-v.nl/post/doing-your-devops-stuff-with-azure-functions-instead-of-logic-apps"&gt;latest post, I&amp;rsquo;ve shown you how you can use Azure Functions in your Microsoft Teams flow to handle errors in your environment&lt;/a&gt;. This stuff works great in a couple of projects I&amp;rsquo;ve worked on, but what would be even more awesome is to reply to a message in Teams when an action has completed after a button is pressed.&lt;/p&gt;
&lt;p&gt;Well, replying &amp;amp; modifying the original message with a status update is quite possible and I&amp;rsquo;ll show you how in this post.&lt;/p&gt;
&lt;h1 id="how-do-i-send-a-reply-to-microsoft-teams"&gt;How do I send a reply to Microsoft Teams?&lt;/h1&gt;
&lt;p&gt;In the image below you can see a message having posted on my Teams channel and a reply is posted.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jan-v.nl/files/b8cff924-34b6-42f4-84fc-2703f66a75ae.png" alt="reply on teams message"&gt;&lt;/p&gt;
&lt;p&gt;This reply has been sent from my Azure Function. If you want to do this, you need to send a &lt;code&gt;HttpResponseMessage&lt;/code&gt; with a status code 200 and a specific header value. This header value is &lt;code&gt;CARD-ACTION-STATUS&lt;/code&gt; and the value will be the message which you will see in the reply.&lt;/p&gt;
&lt;p&gt;The code for this will look something similar to the following.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;static&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;async&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; Run(
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt;	[HttpTrigger(AuthorizationLevel.Function, &amp;#34;post&amp;#34;, Route = null)]&lt;/span&gt; HttpRequest req,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	ILogger log)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#75715e"&gt;// Do your stuff...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#66d9ef"&gt;var&lt;/span&gt; result = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; HttpResponseMessage
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		Headers =
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;			{ &lt;span style="color:#e6db74"&gt;&amp;#34;CARD-ACTION-STATUS&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;$&amp;#34;Timeout of `{request.Timeout}` miliseconds has expired.&amp;#34;&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		},
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		StatusCode = HttpStatusCode.OK
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	};
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; result;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That&amp;rsquo;s all there is to it in order to send a single reply to your message.&lt;/p&gt;</description></item><item><title>Using MSI with Azure Functions and Key Vault</title><link>https://jan-v.nl/post/using-msi-with-azure-functions-and-key-vault/</link><pubDate>Wed, 08 Aug 2018 06:00:00 +0200</pubDate><guid>https://jan-v.nl/post/using-msi-with-azure-functions-and-key-vault/</guid><description>&lt;p&gt;There&amp;rsquo;s a relative new feature available in Azure called &lt;a href="https://docs.microsoft.com/en-us/azure/active-directory/managed-service-identity/overview?WT.mc_id=AZ-MVP-5003246"&gt;Managed Service Identity&lt;/a&gt;. What it does is create an identity for a service instance in the Azure AD tenant, which in its turn can be used to access other resources within Azure. This is a great feature, because now you don&amp;rsquo;t have to maintain and create identities for your applications by yourself anymore. All of this management is handled for you when using a &lt;a href="https://docs.microsoft.com/en-us/azure/active-directory/managed-service-identity/overview?WT.mc_id=AZ-MVP-5003246#how-does-it-work"&gt;System Assigned Identity&lt;/a&gt;. There&amp;rsquo;s also an option to use User Assigned Identities which work a bit different.&lt;/p&gt;
&lt;p&gt;Because I&amp;rsquo;m an Azure Function fanboy and want to store my secrets within Azure Key Vault, I was wondering if I was able to configure MSI via an ARM template and access the Key Vault from an Azure Function without specifying an identity by myself.&lt;/p&gt;
&lt;p&gt;As most of the things, setting this up is rather easy, once you know what to do.&lt;/p&gt;
&lt;h1 id="the-arm-template"&gt;The ARM template&lt;/h1&gt;
&lt;p&gt;The &lt;a href="https://docs.microsoft.com/en-us/azure/app-service/app-service-managed-service-identity?WT.mc_id=AZ-MVP-5003246#asal"&gt;documentation&lt;/a&gt; states you can add an &lt;code&gt;identity&lt;/code&gt; property to your Azure App Service in order to enable MSI.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;identity&amp;#34;&lt;/span&gt;&lt;span style="color:#960050;background-color:#1e0010"&gt;:&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;type&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;SystemAssigned&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This setting is everything you need in order to create a new service principal (identity) within the Azure Active Directory. This new identity has the exact same name as your App Service, so it should be easy to identify.&lt;/p&gt;</description></item><item><title>Using log4net in your Azure Functions</title><link>https://jan-v.nl/post/using-log4net-in-your-azure-functions/</link><pubDate>Thu, 03 May 2018 07:00:00 +0200</pubDate><guid>https://jan-v.nl/post/using-log4net-in-your-azure-functions/</guid><description>&lt;p&gt;As I mentioned in my earlier post, there are 2 options available to you out of the box for logging. You can either use the &lt;code&gt;TraceWriter&lt;/code&gt; or the &lt;code&gt;ILogger&lt;/code&gt;. While this is fine when you are doing some small projects or Functions, it can become a problem if you want your Azure Functions to reuse earlier developed logic or modules used in different projects, a Web API for example.&lt;/p&gt;
&lt;p&gt;In these shared class libraries you are probably leveraging the power of a &amp;lsquo;full-blown&amp;rsquo; logging library. While it is possible to wire up a secondary logging instance in your Azure Function, it&amp;rsquo;s better to use something which is already available to you, like the &lt;code&gt;ILogger&lt;/code&gt; or the &lt;code&gt;TraceWriter&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m a big fan of the &lt;a href="https://logging.apache.org/log4net/"&gt;log4net logging library&lt;/a&gt;, so this post is about using log4net with Azure Functions. As it goes, you can apply the same principle for any other logging framework just the implementation will be a bit different.&lt;/p&gt;
&lt;h1 id="creating-an-appender"&gt;Creating an appender&lt;/h1&gt;
&lt;p&gt;One way to extend the logging capabilities of log4net is by creating your own logging appender. You are probably already using some default file appender or console appender in your projects. Because there isn&amp;rsquo;t an out-of-the-box appender for the &lt;code&gt;ILogger&lt;/code&gt;, yet, you have to create one yourself.&lt;/p&gt;</description></item><item><title>Loading certificates with Azure Functions</title><link>https://jan-v.nl/post/loading-certificates-with-azure-functions/</link><pubDate>Wed, 29 Nov 2017 06:25:00 +0200</pubDate><guid>https://jan-v.nl/post/loading-certificates-with-azure-functions/</guid><description>&lt;p&gt;Using certificates to secure, sign and validate information has become a common practice in the past couple of years. Therefore, it makes sense to use them in combination with Azure Functions as well.&lt;/p&gt;
&lt;p&gt;As Azure Functions are hosted on top of an Azure App Service this is quite possible, but you do have to configure something before you can start using certificates.&lt;/p&gt;
&lt;h1 id="adding-your-certificate-to-the-function-app"&gt;Adding your certificate to the Function App&lt;/h1&gt;
&lt;p&gt;Let&amp;rsquo;s just start at the beginning, in case you are wondering on how to add these certificates to your Function App. Adding certificates is &amp;lsquo;hidden&amp;rsquo; on the SSL blade in the Azure portal. Over here you can add SSL certificates, but also regular certificates&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jan-v.nl/files/46cc506a-e64e-4267-a58c-89af859174c0.png" alt="image"&gt;&lt;/p&gt;
&lt;p&gt;Keep in mind though, if you are going to use certificates in your own project, please just add them to &lt;a href="https://jan-v.nl/post/working-with-azure-key-vault-in-azure-functions"&gt;Azure Key Vault&lt;/a&gt; in order to keep them secure. Using the Key Vault is the preferred way to work with certificates (and secrets).&lt;/p&gt;
&lt;p&gt;For the purpose of this post I&amp;rsquo;ve just pressed the &lt;em&gt;Upload Certificate&lt;/em&gt;-link, which will prompt you with a new blade from which you can upload a private or public certificate.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jan-v.nl/files/8047a43c-7dd3-4c73-8f80-f76e0789deb4.png" alt="clip_image001[4]"&gt;&lt;/p&gt;
&lt;p&gt;You will be able to see the certificate&amp;rsquo;s thumbprint, name and expiration date on the SSL blade if it has been added correctly.&lt;/p&gt;</description></item><item><title>Enable SSL for your Azure Functions</title><link>https://jan-v.nl/post/enable-ssl-for-your-azure-functions/</link><pubDate>Wed, 01 Nov 2017 05:00:00 +0200</pubDate><guid>https://jan-v.nl/post/enable-ssl-for-your-azure-functions/</guid><description>&lt;p&gt;You might remember me writing a post on how you can &lt;a href="https://www.jan-v.nl/post/setting-up-your-site-with-ssl-and-let%E2%80%99s-encrypt-on-azure-app-services"&gt;set up your site with SSL while using Let&amp;rsquo;s Encrypt and Azure App Services&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Well, as it goes, the same post applies for Azure Functions. You just have to do some extra work for it, but it&amp;rsquo;s not very hard.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/sjkp"&gt;Simon Pedersen&lt;/a&gt;, the author of the &lt;a href="https://github.com/sjkp/letsencrypt-siteextension"&gt;Azure Let&amp;rsquo;s Encrypt site extension&lt;/a&gt;, has done some work in explaining the steps on his &lt;a href="https://github.com/sjkp/letsencrypt-siteextension/wiki/Azure-Functions-Support"&gt;GitHub wiki page&lt;/a&gt;. This page is based on some old screenshots, but it still applies.&lt;/p&gt;
&lt;p&gt;The first thing you need to do is create a new function which will be able to do the &lt;a href="https://ietf-wg-acme.github.io/acme/draft-ietf-acme-acme.html#rfc.section.7.5.1"&gt;ACME challenge&lt;/a&gt;. This function will look something like this.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;static&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;class&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;LetsEncrypt&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt; [FunctionName(&amp;#34;letsencrypt&amp;#34;)]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;static&lt;/span&gt; HttpResponseMessage Run(
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt; [HttpTrigger(AuthorizationLevel.Anonymous, &amp;#34;get&amp;#34;, &amp;#34;post&amp;#34;, Route = &amp;#34;letsencrypt/{code}&amp;#34;)]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; HttpRequestMessage req,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;string&lt;/span&gt; code,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; TraceWriter log)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; log.Info(&lt;span style="color:#e6db74"&gt;$&amp;#34;C# HTTP trigger function processed a request. {code}&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;var&lt;/span&gt; content = File.ReadAllText(&lt;span style="color:#e6db74"&gt;@&amp;#34;D:\home\site\wwwroot\.well-known\acme-challenge\&amp;#34;&lt;/span&gt; + code);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;var&lt;/span&gt; resp = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.OK);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; resp.Content = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; StringContent(content, System.Text.Encoding.UTF8, &lt;span style="color:#e6db74"&gt;&amp;#34;text/plain&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; resp;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you can see, this function will read the ACME challenge file from the disk of the App Service it is running on and return the content of it. Because Azure Functions run in an App Service (even the functions in a Consumption plan), this is very possible. The Principal (created in the earlier post) can create these type of files, so everything will work just perfectly.&lt;/p&gt;</description></item><item><title>Use bindings with Azure Functions</title><link>https://jan-v.nl/post/use-bindings-with-azure-functions/</link><pubDate>Thu, 19 Oct 2017 18:45:21 +0200</pubDate><guid>https://jan-v.nl/post/use-bindings-with-azure-functions/</guid><description>&lt;p&gt;(Almost) No one likes writing code meant to store data to a repository, queues, blobs. Let alone triggering your code when some event occurs in one of those areas. Luckily for us the Azure Functions team has decided to use bindings for this.&lt;br&gt;
By leveraging the power of bindings, you don&amp;rsquo;t have to write your own logic to store or retrieve data. Azure Functions provides all of this functionality out of the box!&lt;/p&gt;
&lt;p&gt;Bindings give you the possibility to retrieve data (strong-typed if you want) from HTTP calls, blob storage events, queues, CosmosDB events, etc. Not only does this work for input, but also for output. Say you want to store some object to a queue or repository, you can just use an output binding in your Azure Function to make this happen. Awesome, right?&lt;/p&gt;
&lt;p&gt;Most of the documentation and blogposts out there state you should define your bindings in a file called &lt;code&gt;function.json&lt;/code&gt;. An example of these bindings is shown in the block below.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;bindings&amp;#34;&lt;/span&gt;: [
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;name&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;order&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;type&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;queueTrigger&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;direction&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;in&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;queueName&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;myqueue-items&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;connection&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;MY_STORAGE_ACCT_APP_SETTING&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; },
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;name&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;$return&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;type&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;table&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;direction&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;out&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;tableName&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;outTable&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;connection&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;MY_TABLE_STORAGE_ACCT_APP_SETTING&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The above sample specifies an input binding for a Queue and an output binding for a some Table Storage. While this works perfectly, it&amp;rsquo;s not the way you want to implement this when using C# (or F# for that matter), especially if you are using Visual Studio!&lt;/p&gt;</description></item><item><title>Starting with Azure Functions</title><link>https://jan-v.nl/post/starting-with-azure-functions/</link><pubDate>Thu, 27 Jul 2017 06:12:33 +0200</pubDate><guid>https://jan-v.nl/post/starting-with-azure-functions/</guid><description>&lt;p&gt;Lately, I&amp;rsquo;ve been busy learning more about creating &lt;a href="https://jan-v.nl/post/what%E2%80%99s-up-with-this-serverless-talk"&gt;serverless solutions&lt;/a&gt;. Because my main interest lies within the Microsoft Azure stack I surely had to check out the &lt;a href="https://azure.microsoft.com/en-us/services/functions/?WT.mc_id=AZ-MVP-5003246"&gt;Azure Functions offering&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Azure Functions enable you to create a serverless solutions which are completely event-based. As it&amp;rsquo;s located within the Azure space, you can integrate easily with all of the other Azure services, like for example the &lt;a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus?WT.mc_id=AZ-MVP-5003246"&gt;service bus&lt;/a&gt;, &lt;a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-documentdb?WT.mc_id=AZ-MVP-5003246"&gt;Cosmos DB&lt;/a&gt;, &lt;a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-storage-blob-triggered-function?WT.mc_id=AZ-MVP-5003246"&gt;storage&lt;/a&gt;, but also external services like &lt;a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-sendgrid?WT.mc_id=AZ-MVP-5003246"&gt;SendGrid&lt;/a&gt; and &lt;a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-github-webhook-triggered-function?WT.mc_id=AZ-MVP-5003246"&gt;GitHub&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;All of these integrations are fine and all, but seeing Azure Functions perform in action is still easiest with regular &lt;a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook?WT.mc_id=AZ-MVP-5003246"&gt;HTTP triggers&lt;/a&gt;. You can just navigate with a browser (or Postman) to a URL and your function will be activated immediately. I guess most people will create these kind of functions in order to learn to work with them, at least that&amp;rsquo;s what I did.&lt;/p&gt;
&lt;h1 id="creating-your-azure-functions-app"&gt;Creating your Azure Functions App&lt;/h1&gt;
&lt;p&gt;In order to create Azure Functions, you first have to create a so called Function App in the Azure Portal. Creating such an app is quite easy, the only thing you have to think about is which type of Hosting Plan you want to use. At this time there are 2 options, the Consumption Plan or the App Service Plan.&lt;/p&gt;</description></item><item><title>Splitting unit of work and repository functionality</title><link>https://jan-v.nl/post/splitting-unit-of-work-and-repository-functionality/</link><pubDate>Wed, 22 Mar 2017 11:20:00 +0200</pubDate><guid>https://jan-v.nl/post/splitting-unit-of-work-and-repository-functionality/</guid><description>&lt;p&gt;For years we (a lot of people I know and myself included) have been using the &lt;a href="https://www.martinfowler.com/eaaCatalog/unitOfWork.html"&gt;Unit of Work&lt;/a&gt; and &lt;a href="https://www.martinfowler.com/eaaCatalog/repository.html"&gt;Repository&lt;/a&gt; pattern combined with each other. This makes quite a lot of sense as, in most cases, they both have something to do with your database calls.&lt;/p&gt;
&lt;p&gt;When searching for both of these patterns you&amp;rsquo;ll often be directed to a &lt;a href="https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application?WT.mc_id=AZ-MVP-5003246"&gt;popular article on the Microsoft documentation site&lt;/a&gt;. The sample code over there has a very detailed implementation on how you can implement both of these patterns for accessing and working with your database. I kind of like this post as it goes in great length to describe both the unit of work- and repository pattern and the advantages of using them. I see a lot of projects/companies having implemented the pattern combo like described in the Microsoft article. I can&amp;rsquo;t really blame them as it&amp;rsquo;s one of the top hits when you search for it in any search engine.&lt;/p&gt;
&lt;p&gt;There is a downside to this sample though. It violates the &lt;a href="https://en.wikipedia.org/wiki/Open/closed_principle"&gt;Open/Closed principle&lt;/a&gt; which states&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Whenever you need to add a new repository to your database context, you also need to add this repository to your unit of work, therefore violating the open/closed principle.&lt;/p&gt;</description></item><item><title>Using the decorator pattern with Autofac</title><link>https://jan-v.nl/post/using-the-decorator-pattern-with-autofac/</link><pubDate>Wed, 08 Mar 2017 07:14:00 +0200</pubDate><guid>https://jan-v.nl/post/using-the-decorator-pattern-with-autofac/</guid><description>&lt;p&gt;On a recent project I had to implement the decorator pattern to add some functionality to the existing code flow.&lt;/p&gt;
&lt;p&gt;Not a big problem of course. However, on this project we were using Autofac for our dependency injection framework so I had to check how to implement this pattern using the framework built-in capabilities. One of the reasons I always resort to Autofac is the awesome and comprehensive documentation. It&amp;rsquo;s very complete and most of the time easy to understand. The advanced topics also have a chapter dedicated to the &lt;a href="https://docs.autofac.org/en/latest/advanced/adapters-decorators.html"&gt;Adapter- and Decorator pattern&lt;/a&gt; which was very useful for implementing the decorator pattern in this project.&lt;/p&gt;
&lt;p&gt;I wanted to use the decorator pattern to add some logic to determine if a command should be handled and for persisting database transactions of my &lt;a href="https://www.martinfowler.com/bliki/CQRS.html"&gt;commands and queries&lt;/a&gt;. You can also use it for things like security, additional logging, enriching the original command, etc.&lt;/p&gt;
&lt;p&gt;As the documentation already states, you&amp;rsquo;ll have to register your original command handler as a &lt;a href="https://docs.autofac.org/en/latest/advanced/keyed-services.html?highlight=named#named-services"&gt;Named service&lt;/a&gt;. The Autofac extensions for registering a decorator will use this named instance to add the decorators on to. One thing to remember when you need to add several decorators to your command, you&amp;rsquo;ll have to register each decorator as a named service also, except for the last one!&lt;/p&gt;</description></item></channel></rss>