English
Français

Blog of Denis VOITURON

for a better .NET world

Blazor - Authentication using Cookie

To authenticate a user, Blazor Server uses the same components as ASP.NET Core.

The principle is to inject the service services.AddAuthentication().AddCookie() and call the HttpContext.SignInAsync method, specifying the appropriate Claims.

But the main problem is that Blazor Server uses SignalR to communicate between the web browser and the server. This prevents the correct transfer of cookies. It is therefore necessary to define WebAPIs and to call them using Http.

Global Schema

To help you understand the development of these different steps, I have recorded a video that shows the creation of a Blazor Server project and the integration of all the steps to secure a page or components.

Video - How to create an authenticated Blazor Server project

The complete source code is available here.


Blazor - to catch a 404 not found pages.

To capture all routes that do not correspond to any existing page, there are two techniques:

  1. App.razor

This classic method consists in modifying the NotFound tag of the App.razor page. This works very well, as long as you don’t need the content of the erroneous route.


Microphone, Webcam, software for your meetings or podcasts.

Since many years now, I have been hosting the french podcast DevApps.ms, which talks about news, development and architecture of .NET technologies. On this occasion, I learned about the hardware and software that allow to produce quality podcasts. Scott Hanselman’s site helped me a lot.

For a few months now, the global pandemic has often forced us to homework. For a few days, talking with colleagues using the laptop’s microphone and camera can probably be enough. But after a few months, you probably want to have better image and sound quality.

These are two of these reasons why I want to share my experiences in choosing audio and video equipment. This equipment is certainly not of professional quality, but it has a lot of assets to improve our daily telework.

Teams-Skype


Microsoft Teams - How to create a Bot using C#

In this article, we will create a Microsoft Teams Bot developed in C#, using the Microsoft SDK. Then we will host it in Azure and publish it in your company’s Teams. This way you can easily adapt the C# code to improve the discussion with your Bot.

The steps are :

  1. Developing a Bot in C#
  2. Test the Bot locally
  3. Publish the Bot in Azure
  4. Create a Bot Channels Registration
  5. Setting up the Teams channel
  6. Create a deployment package for Teams
  7. Install the package in Teams

Windows Terminal - Display the GIT status

Recently, Microsoft released a page that explains how to customize Windows Terminal to colour and display GIT status. Git Colored


Azure DevOps - Easy Code coverage

In all projects you develop in .NETCore, it is essential to add a test project :-) And then it becomes very simple to complete this project with a code coverage calculation procedure. Developers will be asked to create test procedures that go through all the branches of your source code. A code coverage rate of at least 80% is very often recommended.


TechDay Conf 2020

This Saturday, I had the chance to participate in the first edition of TechDay Conf, it’s a virtual conference. It includes technical sessions of a few minutes. This conference is dedicated exclusively to application development, cloud transformation and new web framework like Blazor.

My two sessions today are about:

  1. Avoid Entity Framework. Do Object Relational Mapping: french speaking session.
  2. Visual Studio 2019 - Code like a ninja: french speaking session.

SSL certificate for an Azure App Services

In a previous article, I showed you how to create a free SSL certificate via Lets’Encrypt.

The main (or only) problem with Let’s Encrypt is that the certificate has a lifetime of maximum 3 months. This means that you have to renew and install it manually or automatically very regularly.

To avoid this it is necessary to purchase a SSL certificate with an expiration date of up to several years.

Secure web site

Several steps are required to create and install an SSL Certificate in Azure.


How to mock DateTime in Unit Tests (C#)

Today, a developer came to me asking how to test his code that contains a reference to DateTime.Now. Indeed, sometimes your application treats its data differently, depending on today’s date. For example, how do you check the following code, which depends on the current trimester?

int trimester = (DateTime.Today.Month - 1) / 3 + 1;
if (trimester <= 2)
    ...
else 
    ...

Application Insights for your WebAPI

Application Insights is a feature of Azure Monitor. It is an extensible service of Application Performance Management (APM). Use it to monitor your application. It will automatically detect performance anomalies. It includes powerful analysis tools to help you diagnose problems and understand what users are actually doing with your application.

1. Enable Application Insights.

To use this service, it is very simple.

  1. Simply add this service Application Insights to your Azure portal. If you already have a App Service (for your website, for example), you already have the service. Retrieve the Instrumentation Key key from the Overview screen of the Application Insights service.

  2. In your ASP.NET Core project, add the NuGet package ApplicationInsights.

  3. Refer this new service to your Startup class: services.AddApplicationInsightsTelemetry();

  4. Create or modify your file appsettings.json by specifying the Instrumentation Key:

{
  "ApplicationInsights": {
    "InstrumentationKey": "2212b9e0-4715-1765-1746-12cbe02edd67"
  }    
}

Start your project and navigate through the APIs or screens. After a few seconds, you will see the traces appear in the Azure portal.

Application Insights Demo


Languages

EnglishEnglish
FrenchFrançais

Follow me

Recent posts