Book Image

Mastering ASP.NET Core 2.0

By : Ricardo Peres
Book Image

Mastering ASP.NET Core 2.0

By: Ricardo Peres

Overview of this book

<p>ASP.NET is an open source web framework that builds modern web apps and services. This book is your one-stop guide to the new features of ASP.NET Core 2.0, including web APIs and MVC. We begin with a brief overview of the basics, taking you through the MVC pattern, platforms, dependencies, and frameworks. We then move on to setting up and configuring the MVC environment before talking about routing and advanced routing options. Next, we'll look at model binding, controllers and actions, filters, user authentication, and testing.</p> <p>Moving on, you’ll learn about all the aspects of syntax and processes when working with Razor. You’ll be introduced to client-side development and will get to know about the security aspects of ASP.NET Core. We will also look at Microservices with ASP.NET Core. Finally, you’ll find out how to deploy ASP.NET Core to new environments such as Azure, AWS, and Docker. By the end of the book, you will be well versed with development in ASP.NET Core and will have a deep understanding of how to interact with the framework and work cross-platform.</p>
Table of Contents (23 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Routing tables


In Chapter 1, Getting started with ASP .Net Core, we talked about the OWIN pipeline, explaining that we use middleware to build this pipeline. It turns out that there is an MVC middleware that is responsible for interpreting the requests and translating them into controller actions. To do this, we need a routing table. There is only one routing table and it is configurable through the UseMvc method, as can be seen in this example from the default Visual Studio template:

app.UseMvc(routes =>
    {
      routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
    });

What do we see here? The UseMvc extension method of IApplicationBuilder has a parameter that is an instance of IRouteBuilder, which lets us add routes to it. A route is essentially comprised of the following components:

  • A name (default)
  • A template ({controller=Home}/{action=Index}/{id?})
  • Optional default values for each routing parameter (Home, Index)

There are some optional...