URL generation constructs endpoint URLs from route templates and route values. It keeps links and redirects independent of hardcoded paths, so changing an endpoint URL does not require updating every caller. section 6.0 section 6.4
Routing matches a URL to an endpoint and extracts route values; URL generation reverses that process by combining route values with a route template. ASP.NET Core provides LinkGenerator for minimal APIs and other application services. section 6.4
Use the appropriate helper for the application style:
- Use LinkGenerator when generating URLs for minimal APIs or from middleware and other services. section 6.4
- Use IUrlHelper in Razor Pages and MVC controllers; its Page() method accepts a page path and additional route data. section 14.5 section 14.5.1
- Pass values matching route parameters to place them in the path; unmatched values become query-string data. section 14.5.1
Generating a Razor Page URL
A Razor Page can generate a currency-view link with Url.Page("Currency/View", new { code = "USD" }). The helper uses the page route template and the supplied code value. section 14.5.1
Figure 6.8 A comparison between routing and URL generation. Routing takes in a URL and generates route values, but URL generation uses route values to generate a URL.
Compare routing as URL-to-route-value mapping with URL generation as route-value-to-URL construction. section 6.4

