Requesting delegates

Requests are handled by the Use, Run, Map, and MapWhen extension methods. These methods configure the request delegates.

To understand this in detail, let's create a dummy project using ASP.NET Core. Go through the following steps:

  1. Open Visual Studio.
  2. Go to File | New | Project, or click Ctrl + Shift + N. Refer to the following screenshot:
Creating a new project using Visual Studio 2017
  1. From the New Project screen, select ASP.NET Core Web Application.

 

  1. Name your new project (say Chap05_01), select a location, and click OK, as shown in the following screenshot:
Selecting new project template
  1. From the new ASP.NET Core Web Application template screen, choose the API template. Make sure you select .NET Core and ASP.NET Core 2.0.

 

  1. Click OK, as shown in the following screenshot:
  1. Open Solution Explorer. You will see the file/folder structure, as shown in the following screenshot:
Showing file/folder structure of Chap05_01 project

From the dummy project that we have just created, open the Startup.cs file and look at the Configure method, which contains the following code:

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}

The preceding code is self-explanatory: it tells the system to add Mvc to the request pipelines by initiating the app.UseMvc() extension method of Microsoft.AspNetCore.Builder.IApplicationBuilder.

It also instructs the system to use a particular exception page if the environment is in development. The preceding method configures the application.

In the next section, we will discuss four important IApplicationBuilder methods in detail.