2 11 2016
Creating minimal ASP.NET Core web application
By its nature ASP.NET Core application is .NET Core command-line application with some web sites stuff that is set up when application starts. Although Visual Studio has ASP.NET Core web site template that comes with simple default web site and start-up class it’s possible to be even more minimal. This blog post introduces the minimal ASP.NET Core web application.
Creating ASP.NET Core web application
Let’s start Visual Studio and create new ASP.NET Core web application.
For application type let’s select Empty.
Empty application is not still so empty as it can be.
Making application minimal
After creating default ASP.NET Core web application with Visual Studio I removed most of things that come with application:
- wwwroot folder
- bower dependencies
- start-up class.
Image on left shows what’s left when all clutter is removed. Technically the Dependencies folder is also not needed but as it is something that Visual Studio shows dynamically it’s not possible to remove it.
There’s one problem now. The application doesn’t build anymore.
Let’s open Program.cs and make it look like shown below. After adding Kestrel web server to web host the web host is configured to response “Hello, world” to every request that comes in. Without this there will be no response and browsers see that web site as not alive.
public class Program
public static void Main(string args)
.Configure(a => a.Run(r => r.Response.WriteAsync(“Hello, world”)))
Running the web application results in something like shown on screenshot below.
This response is given to all requests no matter what is asked.
Although it is possible to create small and minimal ASP.NET Core web site from Visual Studio template the resulting site is still not as minimal as possible. After removing all clutter and modifying web host to response “Hello, world” to all requests the application got as minimal as possible. It is actually good example about how using ASP.NET MVC is not mandatory when creating ASP.NET Core web applications.