ASP.NET Core › Endpoint Metadata, Route Constraints & Templates
How do complex/composite route segments (combining literal text and a parameter in the same segment, like {fileName}.{extension}) work?
IntermediateAnswer
A single URL segment can combine literal characters and multiple parameters, like {fileName}.{extension}, letting the routing system parse a segment like 'report.pdf' into fileName='report' and extension='pdf' -- though this pattern requires unambiguous delimiters (like the literal dot here) since the router needs to determine where one parameter ends and the next literal/parameter begins.
app.MapGet("/files/{fileName}.{extension}", (string fileName, string extension) => {
// GET /files/report.pdf -> fileName = "report", extension = "pdf"
return DownloadFile(fileName, extension);
});Real-world example A file-serving endpoint splits a single URL segment like 'report.pdf' into separate fileName and extension route values using a composite route segment, letting handler code work with each part independently without manual string splitting.