Monday, February 18, 2019

Adding UseDeveloperExceptionPage Middleware

Exception Handling is an integral part of any application, if exceptions are not handles we will see the system exception page like status code 500, this will not provide much information to the developers to investigate on the exception. In the previous .Net Framework MVC by default the stack trace and line information will be displayed in the browser, but in .Net core it shows a generic error message.

Sunday, February 17, 2019

Adding Middleware to Asp.Net Core

In the previous posts we saw a simple HelloWorld application which displays a message in the browser when the application runs. In this post we will further enhance the application by adding another Middleware to the execution sequence.

Hello World example in Asp.Net Core

In the previous posts we saw about what Asp.Net Core is, its features and its advantages. Let us get started with a simple Hello World example in Asp.Net Core. We will use Visual Studio for this example. We can use Visual Studio Code also for a simple example like this, but for complex example Visual Studio is a better tool, hence we will use Visual Studio for this example.

Before we begin the example make sure that .Net Core SDK is installed in the machine, also install Visual Studio. In this example we will use Visual Studio 2017. Let’s get started.

Sunday, February 10, 2019

Asp.Net Core Host and Logging Configuration

A simple Asp.Net core application contains a Startup.cs file and a Program.cs file. We saw that the Startup file is used to define the execution pipeline to process Http requests and to inject services. In this post we shall see about the role of Program.cs file.

The Program.cs file in an Asp.Net core application contains logic to define the host configuration and logging configuration. It has the public static void Main() method which is the entry point of the application.

The Main() method calls CreateWebHostBuilder, which in-turn calls WebHost.CreateDefaultBuilder, this method performs the following tasks under the hood.