liveBook · Manning

Static path segment

As explained in Pro ASP.NET Core 7, Tenth Edition

A literal segment is a route-pattern segment that matches a fixed string in a URL path.

A static path segment, also called a literal segment, matches one fixed string in a URL path. In the pattern "capital/uk", the first segment must be "capital" and the second must be "uk", so only /capital/uk matches. section 13.1.5

Literal segments make routes more specific and help distinguish endpoints. They contrast with segment variables such as {country}, which match varying values and expose them through HttpRequest.RouteValues. section 13.1.5 section 27.1

Use literal segments when you need to:

  • Give a route a recognizable, fixed URL prefix, such as controllers/{controller=Home}/{action=Index}/{id?}. section 27.1
  • Separate otherwise similar endpoint patterns by adding specificity before considering route order or other routing configuration. section 13.3.2

A fixed route alongside variable routes

app.MapGet("capital/uk", new Capital().Invoke); app.MapGet("capital/{country}", Capital.Endpoint); The first mapping accepts only /capital/uk; the second accepts different country values and reads the matched value from RouteValues.

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Defines matching behavior and demonstrates endpoint mappings, but stops short of detailed route-selection internals.
Examples
Demonstrates /capital/uk, controllers/{controller}/{action}/{id?}, and capital/{country} alongside variable route patterns.
What it assumes
Assumes basic URL routing and endpoint mapping while contrasting fixed segments with route parameters.
What you can do after
Build route maps that combine fixed URL segments with parameters and reduce ambiguity through greater specificity.
How it connects
Connects URL routing with route parameters, endpoint mapping, route precedence, and route constraints.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.