Use Selenium Webdriver on Ubuntu with .NET Core 7

First update your system

apt update
apt upgrade

Next download google-chrome

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

Next install ‘google-chrome’

dpkg -i google-chrome-stable_current_amd64.deb

If you have a problem with your dependencies after the previous step, run the following command then try again the previous step.

sudo apt -f install

Verify your version of google-chrome

google-chrome --version
# Google Chrome 123.0.6312.86

Create a new console program

dotnet new console -n SeleniumExample
cd SeleniumExample

Install required packages

dotnet add package Selenium.WebDriver
dotnet add package Selenium.WebDriver.ChromeDriver

Edit your Program.cs file and replace its contents with the code below.

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

class Program
{
    static void Main(string[] args)
    {
        // Set up the ChromeDriver
        var options = new ChromeOptions();
        options.AddArgument("--headless");

        using var driver = new ChromeDriver(options);

        // Navigate to a website
        driver.Navigate().GoToUrl("https://www.google.com");

        // Wait for the results to load and display the title
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
        Console.WriteLine(driver.Title);

        // Close the browser
        driver.Quit();
    }
}

Run the program, it should show the title of the google.com webpage

Share

Set static IP on Ubuntu 24.04

First check your current ip and gateway settings with the command “ip a” and “ip r”.

Edit the file /etc/netplan/00-installer-config.yaml, place the following contents in it:

network:
  renderer: networkd
  ethernets:
    eth0:
      addresses:
        - 172.29.0.2/24
      nameservers:
        addresses: [1.1.1.1,8.8.8.8]
      routes:
        - to: default
          via: 172.29.0.1
  version: 2

The gateway address can be determined by executing ip r

Share

Remove obsolete nuget package references

To get rid of deprecated nuget packages in your solution follow the procedure below.

In Visual Studio first manage the nuget packages for your project (or solution) by right clicking the project in the solution explorer and choose Manage NuGet Packages…

Then the deprecated packages will show up in the list:

To remove those packages you have to remove them from the project file (or do an uninstall with the nuget package manager). I prefer to do this in the project file. So open the project file and remove the package entry (marked lines in the image below).

Now you have to add the FrameworkReference item to the project file. See the project file below and checkout the marked lines.

Check also this link for a more verbose explanation.

Share

GIT – remove unused branches

If you have some branche son your remote repository that are no longer in use you can delete them by following the steps below (make sure no one is updating these branches anymore).

First make sure you are not on the branch you want to delete

git checkout master

Then list the branches (remote and local) defined in your local repository

git branch -a

Now delete the branch with name CompanyEntity (casesensitive) from local if its (still) there

# Delete local
git branch -d CompanyEntity
# Deltete remote
git push origin --delete CompanyEntity

Now to update the branches for a repository at another location (deleting stale branches) execute the command:

git fetch --prune

The local branches will be synced with the remote branches

Share

LetsEncrypt certificate renewal behind proxy

When deploying a .NET Core website on your domain, you likely utilize a reverse proxy to route traffic from ports 443 and 80 to your Kestrel web server. The configuration for this in Apache is as follows.

The line ProxyPass /.well-known/acme-challenge ! is included to ensure that Let’s Encrypt can successfully renew the certificate.

The other ProxyPass lines are for blazor to connect to the server.

ProxyRequests On
ProxyPreserveHost On
ProxyPass /.well-known/acme-challenge !
ProxyPassMatch ^/_blazor/(.*) http://0.0.0.0:5003/_blazor/$1
ProxyPass /_blazor ws://localhost:5003/_blazor
ProxyPass / http://0.0.0.0:5001/
ProxyPassReverse / http://0.0.0.0:5001/

Share

Ubuntu journalctl

If you want to view the log for a systemd service you can use the journalctl command. Basic Log Viewing: To view the logs for your prog-app service, you can use the following command:

sudo journalctl -u service-app

Tail Logs: If you want to follow the log in real-time, as new entries are added, use the -f flag:

sudo journalctl -fu service-app

Filter by Time: If you’re interested in logs from a specific time period, you can use --since and --until options. For example:

sudo journalctl -u service-app --since "2023-11-27" --until "2023-11-28"

Viewing the Most Recent Entries: To see the most recent entries, you can combine journalctl with other commands like tail. For example:

sudo journalctl -u service-app | tail -n 20
Share

Mollie Payments with C# / ASP.NET MVC Net Core

This post describes how to implement Mollie payments in your ASP.NET MVC Web application.

Begin by setting up an account at my.mollie.com. Ensure that you fully complete the registration process, which includes adding at least one payment method.

Following this, launch Visual Studio (or Visual Studio Code) and create a new MVC web application. The next step is to integrate the Mollie API. Do this by adding the NuGet package ‘Mollie.Api‘. As of the writing of this post, the current version is 3.3.0.

Continue reading
Share

LetsEncrypt request certificate error

Invalid host in redirect target “subdomain.domain.io.well-known”

When you get this error while requesting a new certificate you probably have a wrong redirect statement in your apache configuration.

The “redirect permanent” in the port 80 section should end with a / (or remove this entry while requesting a new certificate)

Share