Practical .NET, software, and AI tutorials by Gerard Beckerleg, a developer in Sydney.
- Specifying a Redis Connection String with Dot Net Core and Microsoft.Extensions.Caching.StackExchangeRedis
The documentation seems to be a bit sparse when it comes to specifying connection strings with the Microsoft.Extensions.Caching.StackExchangeRedis NuGet package. If you have any type of non standard configuration then the secret is to pass the connection string in its entirety to options.configuration with additional options separated by a comma. For example, if you wanted to specify a non standard port and use database 1 instead of the default 0 then you could use the following connection string:
- XSRF or CSRF with Angular and Dot Net Core Web API
Turns out adding XSRF, CSRF, See-Surf or whatever the name we call it now to an Angular app with a .NET Core Web API is really really easy. Angular is set up by convention to expect a cookie with the name XSRF-TOKEN.
- How to Optimize All JPG and PNG Files in a Folder Using the Windows Command Line
Images on the internet should always be optimized where possible to reduce the load time of your websites. Of course the best solution is to use a CDN but sometimes for whatever reason like me you inherit some folders full of unoptimized images you can run the following commands to reduce the load on your server. These could also be added to batch files and run in the scheduler if required.
- How to Add Microsoft's Console Log Provider to .Net Core 2.2 Console Application using the built-in Service Provider
Starting with an empty .NET Core Console Application add the following packages: Microsoft.Extensions.DependencyInjection Microsoft.Extensions.Logging Microsoft.Extensions.Logging.Console Instantiate Microsoft’s Dependecy Injection Service Provider. var serviceProvider = new ServiceCollection().BuildServiceProvider(); Register the Console Logging Provider dependency with the Service Provider using Microsoft’s extension methods var serviceProvider = new ServiceCollection().AddLogging(cfg => cfg.AddConsole()).BuildServiceProvider(); By default the lifetime of the logging service is set to Singleton.
- Decommissioning Old Databases
Occasionally I inherit an old development database server containing many databases and I usually have no idea which are no longer in use. I came across the following script that allows you to see the last time a database was accessed:
- Find Pair With Given Sum in Array
As I’m moving more and more into management I need ways to keep my coding foo fresh so I have taken to solving small problems from various sites on the internet in my spare time. I also miss that feeling of being in the zone and fully engaged in something just difficult enough to stretch myself.
- Hugo - Failed to find a valid digest in the 'integrity' attribute for resource
After cloning my Hugo site to a new machine and running: hugo server No CSS would load and the console was reporting the following error: Failed to find a valid digest in the 'integrity' attribute for resource The problem was that the CSS for the theme is using the integrity attribute to allow the browser to guarantee that the file downloaded has not been manipulated from the source. For some reason Hugo was regenerating the CSS with a different hash than what was expected, I suspect this might be a git line ending issue.
- Hugo NoSuchKey on Sub Folders After Deploying to Amazon S3 and CloudFront
After deploying this blog to Amazon S3 with CloudFront the main page rendered correctly but any pages in sub folders like /posts or /posts/post-vanity-url would recieve the following error: <Error> <Code>NoSuchKey</Code> <Message>The specified key does not exist.</Message> <Key>{path}</Key> <RequestId>{RequestId}</RequestId> <HostId> {HostId} </HostId> </Error> Hugo uses directory URLs by default (posts/post-vanity-url) instead of files names (/posts/post-vanity-url/index.html). S3 is an object storage system not a file system. When a directory URL is passed to the server, it looks for the default root object in that directory. Asking for a directory fails to retrieve the index.html file in that folder.
- Building Hugo Extended on AWS CodeBuild
After upgrading my Hugo theme to the Hyde inspired Hyde-Hyde theme I also needed to switch from the standard Hugo build to the extended build in order to use the pipes feature. After successfully installing the new theme locally I hit into problems running the extended version of Hugo on AWS CodeBuild. First I received the following error:
- Open ID & OAUTH 2.0
I do security work often but not often enough that I don’t end up Googling many of the terms and concepts every time. Here is a list of the best articles as a quick goto: OAUTH-OPENID: YOU’RE BARKING UP THE WRONG TREE IF YOU THINK THEY’RE THE SAME THING OpenID versus OAuth from the user’s perspective An introduction to OpenID Connect in ASP.NET Core Creating your own OpenID Connect server with ASOS: introduction