UriGeneration 2.0.11

.NET 6.0
dotnet add package UriGeneration --version 2.0.11
NuGet\Install-Package UriGeneration -Version 2.0.11
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UriGeneration" Version="2.0.11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UriGeneration --version 2.0.11
#r "nuget: UriGeneration, 2.0.11"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UriGeneration as a Cake Addin
#addin nuget:?package=UriGeneration&version=2.0.11

// Install UriGeneration as a Cake Tool
#tool nuget:?package=UriGeneration&version=2.0.11

Uri Generation

Strongly typed URL generation for ASP.NET Core:

string? uri = _uriGenerator.GetUriByExpression<InvoicesController>(
    c => c.GetInvoice(2));


  • Extracts action name, controller name, and route values from expression
  • Delegates URL generation to LinkGenerator
  • Supports ActionName, Area, NonAction, NonController, FromBody, FromForm, FromHeader, and FromServices attributes
  • Supports IFormFile, IFormFileCollection, IEnumerable<IFormFile>, CancellationToken, and FormCollection types
  • Supports specifying an endpoint name
  • Supports Controller and Async suffixes
  • Supports LinkOptions
  • Supports bypassable caching

Specifying an endpoint name:

If you use named attribute routes:

[HttpGet("api/invoices/{id}", Name = "ApiGetInvoice")]
[HttpGet("invoices/{id}", Name = "GetInvoice")]
public InvoiceResource GetInvoice(int id)

or dedicated conventional routes:

    name: "ApiGetInvoice",
    pattern: "api/invoices/{id}",
    defaults: new { controller = "Invoices", action = "GetInvoice" });
    name: "GetInvoice",
    pattern: "invoices/{id}",
    defaults: new { controller = "Invoices", action = "GetInvoice" });

you can specify an endpoint name to generate an endpoint-specific URL:

string? uri = _uriGenerator.GetUriByExpression<InvoicesController>(
    c => c.GetInvoice(2),
string? uri = _uriGenerator.GetUriByExpression<InvoicesController>(
    c => c.GetInvoice(2),

For more information on endpoint names, see ASP.NET Core documentation.


Extracting values from expression trees does introduce some overhead. To partially work around this problem, UriGeneration uses ASP.NET's CachedExpressionCompiler, so that equivalent route values' values' expression trees only have to be compiled once.

Additionally, it uses its internal Microsoft.Extensions.Caching.Memory.MemoryCache instance to cache extracted controller names, action names, and route values' keys within the scope of the application lifetime.

This means that, for example, on 2017 Surface Book 2 you are able to generate 100000 URLs in a second using a template like this: https://localhost:44339/api/invoices/{id}.


  • Install UriGeneration via NuGet Package Manager, Package Manager Console or dotnet CLI:
Install-Package UriGeneration
dotnet add package UriGeneration
  • Register UriGeneration in a service container (each cache entry will have a size of 1):
builder.Services.AddUriGeneration(o =>
    o.SizeLimit = 500;
    o.CompactionPercentage = 0.5;
  • Request an instance of IUriGenerator singleton service from any constructor in your app:
public class InvoicesController
    private readonly IUriGenerator _uriGenerator;

    public InvoicesController(IUriGenerator uriGenerator)
        _uriGenerator = uriGenerator;


To see the default log messages, enable LogLevel.Debug in the logging configuration.


Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.11 197 1/19/2023
2.0.10 201 12/30/2022
2.0.9 243 11/26/2022
2.0.8 257 11/1/2022
2.0.7 307 9/16/2022
2.0.6 369 9/13/2022
2.0.5 310 9/10/2022
2.0.4 311 9/10/2022
2.0.3 321 9/10/2022
2.0.2 316 9/9/2022
2.0.1 309 9/9/2022
2.0.0 309 9/9/2022
1.1.1 336 8/25/2022
1.1.0 319 8/25/2022
1.0.4 313 8/18/2022
1.0.3 299 8/18/2022
1.0.2 302 8/18/2022
1.0.1 304 8/18/2022
1.0.0 307 8/18/2022
0.1.76 311 8/18/2022
0.1.75 321 8/10/2022