Getting ready

We need to modify the code contained inside the Configure() method of our Startup class. It is here that we set up middleware in an ASP.NET Core application. In Chapter 10Exploring .NET Core 1.1, we saw that our Configure() method already contained two pieces of middleware. The first is a piece of middleware that will display a developer exception page when an unhandled exception is caught. The code looks as follows:

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

This will display any error messages which is useful for debugging the application. Typically, this page would contain information such as a stack trace. It is only installed when the application is in development mode. When you first create an ASP.NET Core application, it is in development mode.

The second middleware is the app.Run() and will always be present in your application. In Chapter 10Exploring .NET Core 1.1 , it would always respond with the current date. Think of middleware as gate keepers. All HTTP requests coming in to your application must pass through your middleware.

It is also important to know that the order you add your middleware is important. In the app.Run() middleware, we did a context.Response.WriteAsync(). Any middleware added after this will not be reached because the processing pipeline terminates in app.Run(). This will become clearer as we move on.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.245.140