13 Using URL routing

 

This chapter covers

  • Understanding how routes can be used to match request URLs
  • Structuring URLs patterns to match requests
  • Matching requests using routes

The URL routing feature makes it easier to generate responses by consolidating the processing and matching of request URLs. In this chapter, I explain how the ASP.NET Core platform supports URL routing, show its use, and explain why it can be preferable to creating custom middleware components. Table 13.1 puts URL routing in context.

Note

This chapter focuses on URL routing for the ASP.NET Core platform. See part 3 for details of how the higher-level parts of ASP.NET Core build on the features described in this chapter.

13.1 Preparing for this chapter

13.1.1 Understanding URL routing

13.1.2 Adding the routing middleware and defining an endpoint

13.1.3 Simplifying the pipeline configuration

13.1.4 Understanding URL patterns

13.1.5 Using segment variables in URL patterns

13.1.6 Generating URLs from routes

13.2 Managing URL matching

13.2.1 Matching multiple values from a single URL segment

13.2.2 Using default values for segment variables

13.2.3 Using optional segments in a URL Pattern

13.2.4 Using a catchall segment variable

13.2.5 Constraining segment matching

13.2.6 Defining fallback routes

13.3 Advanced routing features

13.3.1 Creating custom constraints

13.3.2 Avoiding ambiguous route exceptions

13.3.3 Accessing the endpoint in a middleware component

Summary