Web Log

Server-side, client-side, code snippets, scripts, automation, best practices, proven approaches, tips & tricks...

Handling data concurrency in EF Core and ASP.NET Core WebAPI

Data concurrency in Entity Framework Core
 
0
Entity Framework Core implements optimistic concurrency strategy which is opposite to pessimistic concurrency strategy. Lets's first clear out what are main differences between these two approaches in concurrency control. Optimistic concurrency control allows multiple processes to access and modify data without any explicit lock on the data ... read more

Setting up Swagger to support versioned API endpoints in ASP.NET Core

Adding Swagger support for versioned REST Web API endpoints
 
0
Versioning of your endpoints is important especially if you have 3rd party dependent clients of your REST API service. Any change in your endpoint, for example in data structure may impact clients even if it is backward compatible, clients may process your endpoint data in different ways, so even adding one additional property to your model may also impact functionality of the client which is consuming your endpoint. Prerequisites ... read more

HTML5 localStorage with expiry with vanilla JavaScript

Using HTML5 localStorage with expiry
0
HTML5 comes with a lot of handy features which can really improve user experience of your web application significantly if you use them wisely. Caching cold data on the client, such as lookups can significantly save the amount of traffic, page load time and even you backed services load. One of the HTML5 features that can help you do this are sessionStorage and localStorage ... read more

Extending Serilog with additional values to log

Adding additional information to log in .NET Core application with Serilog
0
If you are building .NET Core application your choice for logger library is most likely Serilog. It is really powerful and easy to use library which allows you easy logging in all levels in your application. One of the best features it has is easy extending of the data you want to have in your logs ... read more

Logging EF Core actions to a file using Serilog

Log Entity Framework Core using Serilog in .NET Core application
0
Logging is an essential part of the application. It gives you insights which allows you to see your application behavior or even user behaviour and actions taken by them in the application.Serilog is most probably the most popular library for logging in .NET Core applications ... read more

Different ways to auto-generate Docker image tags

Various ways to auto-generate Docker image tags and use latest tag
0
Tagging Docker images is important to keep track of versions of the service running and to easily roll back in case of faulty behavior of the application. The version strategy which is the most clear and understandable is tagging image with version of the application for example ... read more

Using custom request and response serializers in ASP.NET Core

Configuring input and output serailzer/deserialier in ASP.NET Core pipeline
 
0
This is not a new subject and the support for handling WebApi input and output was introduced in .NET Core 2.0 and it's been there since then. There are couple of useful pages out there and it is even well documented on Microsoft official page Custom formatters in ASP.NET Core Web API ... read more

Setting up .NET Core development environment on Ubuntu Linux

A quick guide for switching from Windows based Visual Studio 2017 to Visual Studio Code
0
With growing popularity of dotnet Core, Git and Docker, developers who used to work mainly on Windows are now getting used to CLI environment and obviously Linux. Windows is still a development environment platform of choice, bit since Microsoft already developed and published Visual Studio Code as a cross platform IDE for Windows, Linux and Mac. Although it is still not mature as Visual Studio 2017, it is a decent tool for .NET Core applications development ... read more

Reloading the cache automatically once expired is ASP.NET MVC

Load values to in memory cache as soon as they expire in ASP.NET MVC
0
In memory caching is not a bullet proof way of caching data in an application, especially if this application is distributed. The lack of synchronization between nodes can cause you application to misbehave showing wrong data or even throwing exceptions and crashing. This is one of the main reasons why distributed caching is the best way of doing the caching in your web application. But not all applications you might be developing need to run as distributed on multiple machines ... read more

Simple script for building and publishing .NET Core application to Docker

Build and publish .NET Core application to Docker container or Kubernetes
0
Recently I wanted to try to spin up a simple .NET Core application on my local cluster which I built in my previous article Manual setup of Kubernetes cluster on a Virtual Machine with kubeadm. The problem I had is that I needed to test applications in this cluster and deploy them as service in order to monitor potential issues behavior. As deployment of Kubernetes service needs an image to pull from, I decided to use dockerhub to push my test images, but they first needed to be created. ... read more

Get most visited pages of your website from Google Analytics using C#

List most visited website pages from Google analytics in your .NET application code
0
If you have a website like this one with articles and you would like to suggest most visited articles to your visitors, there are few ways to do this. One of them is definitely a custom solution that can track and store count of every visit per page you have, or without any re-inventing of wheel you can just hook to Google Analytics API to pull the data ... read more

Creating Windows service and Linux daemon with the same code base in .NET

Cross-platform service with C# and .NET Framework
 
0
Few months back I wrote an article on how to create Linux daemon in .NET Core using generic host class introduced in 2.1 version of .NET Core. This code works just great on Linux OS when configured as a daemon in systemd and provides more less same concept you would have with Windows Service written in .NET Framework 4.x. The code works just fine on both Windows and Linux hosts, but because it is compiled as a Console Application, you do not really get to run it on your Windows machine as a Service ... read more

Minify ASP.NET MVC Core response using custom middleware and pipeline

Html response content minification on the fly in ASP.NET Core
0
For my website, since it runs on Umbraco 6 and it is basically ASP.NET MVC application. To reduce load time and increase website performances I decided to alternate the response of the application and minify it using simple regular expression. Initially I was trying to do this with YUI Compressor library which has .NET port as NuGet YUICompressor.NET which works fine in most of the cases, but in my case does not skip PRE tags which I use for code snippets on the website ... read more

JavaScript

read more

Umbraco CMS

read more

.NET

read more

SQL/T-SQL

read more