Post-Redirect-Get and TempData with ASP.NET Core

The Post-Redirect-Get (PRG) pattern prevents duplicate form submissions when the user refresh the page. Here's the sequence diagram: As you can see, the server query the database twice to display the page to the user. This is inefficient, but how can you improve this? The time between the two requests is very short (about 1 second). So, maybe you can store the object in memory, and reuse it when the user… [read more]

ASP.NET Core - Precompiling razor views

Improving the startup time of your website is important. There are many reasons for a website to take times to get ready: loading lots of dll, loading data, compiling views, etc. In this post, I'll explain how to reduce the startup time by precompiling razor views. The view precompilation is a build step that generates a DLL from the cshtml. Instead of doing the view compilation at runtime the first time… [read more]

FileSystemWatcher intermittently throws an exception on Linux

In my quest of hosting my ASP.NET Core web sites on Linux, I encounter an intermittent exception: System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached. at System.IO.FileSystemWatcher.StartRaisingEvents() at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed() ... This exception occurs when I instanciate a FileSystemWatcher. To protect… [read more]

Publishing an ASP.NET Core website to a Linux host

I recently move my web site to a Linux host, remember, .NET Core is multi-platform 😃 This choice is mainly motivated by the price. Indeed, you can find many cheap VPS providers (Virtual Private Server) on the internet. For instance, you can choose OVH. They have great VPS for about 3€ per month (I'm not paid by them, but I've been using their services for a few years without any issue). Hosting a site on… [read more]

Improve the security of your website using SSL and HSTS with ASP.NET Core

Using HTTPS on your website provides additional security for your users: confidentiality, integrity and authentication. Using Let's encrypt, you can get a free certificate and start using HTTPS. If you aren't using HTTPS yet, you can read my previous blog post about setting up Let's encrypt for your website. But HTTPS isn't perfect, and some people has found multiple attacks: CRIME, BEAST, POODLE or SSL… [read more]

Minify CSS and JavaScript files with Visual Studio and ASP.NET Core

In the last two posts, I wrote about improving ASP.NET Core web site performance. The first one was about caching files to ensure the browser download them only once. The second is about reducing the size of the server response with gzip compression. Today, I'll stay on improving performance with bundling and minifying stylesheets and JavaScript files. Minifying consists of reducing the size of the… [read more]

Enabling gzip compression with ASP.NET Core

In the last post, I wrote about improving performance of a web application by caching static resources. Another great performance improvement, is about compressing response. Main browsers support deflate, gzip, and more recently brotli. If you host your ASP.NET Core application using IIS or nginx, you may already take advantages of the compression. However, if you do not use a reverse proxy that provides… [read more]

Caching static resources forever with ASP.NET Core

Caching static resources like stylesheet, JavaScript or image files allows to improve the performance of your website. On the client side, a static file will always be loaded from the cache which reduce the number of requests to the server and so, the time to get the page and its resources. On the server side, as they are less requests, the server can handle more clients without upgrading the hardware.… [read more]