Skip to content

Instantly share code, notes, and snippets.

@joerivanarkel
joerivanarkel / .ConnectionString.md
Last active April 25, 2022 12:38
Dotnet Secrets Setup

Dotnet Secrets Setup

To setup dotnet secrets, you run the dotnet user-secrets init command. This readies the project for the use of dotnet secrets. To add a secret, you use the dotnet user-secrets set {Name} "{Value}". You must redo this for every project in which you are using the secret. Simply add the name of the secret and the value to create an secret. it is stored locally in %appdata%. On GitHub it is possible to use Environment variables to fill in the gaps left by dotnet secrets.

In the underlying code is a example of how to apply dotnet secrets. To fetch a secret this underlying piece of code is used. Here we create a ConfigurationBuilder and fill it with the secrets per project/class. From there it is as easy as querying the list for the right value.

@joerivanarkel
joerivanarkel / .Azure Container.md
Last active April 25, 2022 13:00
Docker and Azure Containers

Azure Container

Creating a container instance in Azure follows the basic steps of building an image, creating a container and pushing to registry from Docker Container. The easier way is to push a container directly from VSCode to an Azure Container Registry. Otherwise you can create a Container Instance from a Azure Container Registry container in the Azure Portal, but make sure the right port is opened. Underneath is a GitHub workflow which can automatically create, build and push an image to a container registry on commit.

Deploying to an Azure Web App

Firstly you have to create a project and write the code that you would want to deploy to an Azure Web App. Then you have to publish the project, which can be easily done by running the dotnet publish command. Then you can deploy it by using the Azure Extension VSCode or internally in Visual Studio.

While deploying in VSCode, i ran into two errors. Firstly it was unable to find the appService.preDeployTask task. This can be fixed by changing the value to publish in settings.json. Secondly it was unable to find the project file. Here i changed the deployment source to LocalGit. This does require you to commit your code before deploying, but it does fix the issue.

@joerivanarkel
joerivanarkel / MicrosoftIdentity.md
Last active May 9, 2022 19:09
Creating a Web App using Microsoft Identity and Azure Active Directory

Microsoft Identity an Azure Active Directory authentication

In this document i describe how to create a Blazor app using Microsoft Identity and Azure Active Directory. This is easily done in Visual Studio, as it is integrated in the project creation.

During the creation you have to select Microsoft Identity as the form of authentication. It is also possible to immediately configure Docker, to run this app in a container. You will shown a configuration screen upon completion of construction. When you configure Microsoft Identity, you will firstly have to select an account created in a Azure Active Directory. Secondly you'll have to create a Azure Active Directory App Registration. Afterwards you get a list of options you don't have to configure.

Publishing to Azure Container Service

In Visual Studio it keeps track of the connected services and gives the configuration options upon publishing. This would bee the same as the previous one, but replaces the secrets.json with an Azure key Vaults option.

using System.Globalization;
List<DateTime> GetDatesFromISOWeek(int year, int week)
{
var result = new List<DateTime> {};
for (int i = 1; i <= 5; i++)
{
var weekDay = Enum.GetValues(typeof(DayOfWeek)).Cast<DayOfWeek>().Where(((n, x) => x == i));
result.Add(ISOWeek.ToDateTime(year, week, weekDay.FirstOrDefault()));