Skip to Content
Learn
Introduction To ASP.NET Middleware
Start-Up Files

We know middleware is made up of delegates and these delegates are called in sequence, but let’s discuss how that sequence is determined. When we create a new web application in Visual Studio, the Program class and the Startup class are added by default.

The Program.cs file is important because it contains the Main() method. The Main() method is where the application will start and it calls the method, CreateHostBuilder(). CreateHostBuilder() is important because it’s responsible for certain configuration settings for our application, but the focus of our attention will be on the UseStartup() method.

namespace TestWebApplication { public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); } }

If you ever have trouble reading these snippets, copy and paste them into a text editor on your own computer.

Instructions

When we create a new ASP.NET web application, two important files, Program.cs and Startup.cs are added by default.

Folder Icon

Sign up to start coding

Already have an account?