Book Image

ASP.NET Core 2 Fundamentals

By : Onur Gumus, Mugilan T. S. Ragupathi
Book Image

ASP.NET Core 2 Fundamentals

By: Onur Gumus, Mugilan T. S. Ragupathi

Overview of this book

The book sets the stage with an introduction to web applications and helps you build an understanding of the tried-and-true MVC architecture. You learn all about views, from what is the Razor view engine to tagging helpers. You gain insight into what models are, how to bind them, and how to migrate database using the correct model. As you get comfortable with the world of ASP.NET, you learn about validation and routing. You also learn the advanced concepts, such as designing Rest Buy (a RESTful shopping cart application), creating entities for it, and creating EF context and migrations. By the time you are done reading the book, you will be able to optimally use ASP.NET to develop, unit test, and deploy applications like a pro.
Table of Contents (14 chapters)

Our First Controller


Before creating the controller, we need to remove the followingapp.Run statement as this will return Hello World! for all the incoming requests. As we want incoming requests to be handled by the controllers, we need to remove the following code from the Configure method of the Startup class:

app.Run(async (context) =>
{
  await context.Response.WriteAsync("Hello World!");
};

We have installed ASP.NET Core in our application. So, we are geared up for creating our first ASP.NET Core controller. Create a folder with the name Controllers and add a new controller from the context menu, as shown in the following screenshot:

Context basically represents the request-response pair along with other metadata necessary to process the request. 

Note

For people who used OWIN to develop your own web custom framework without using MVC, it is analogous to IOwinContext. And apparently, app.Run would be a good entry point to handle HTTP requests manually or for writing a custom framework...