Advertisement
Intermediate 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?

Short answer

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…

Save ASP.NET Core mock interview
Advertisement
AModel answer
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.
Likely follow-ups
  • What ambiguity issues can arise with composite segments lacking a clear literal delimiter?
  • How does this compare to just accepting the full segment as one string and splitting it manually in the handler?
Related topics