Skip to content

IUriResolver Interface

Provides functionality for generating URIs for controller actions and static content within an application.

C#
public interface IUriResolver

Derived
UriResolver

Methods

IUriResolver.Action(string, string, object) Method

Generates an absolute URI for a specified controller action, enabling action methods to be easily referenced across the application for things like redirects or link generation.

C#
System.Uri Action(string actionName, string controllerName, object? routeValues=null);

Parameters

actionName System.String

The name of the action method within the controller.

controllerName System.String

The name of the controller that contains the action method.

routeValues System.Object

An object containing the route values for the action method. These values are used to construct the query string and populate parameters in the route template. This parameter is optional.

Returns

System.Uri
An absolute URI as a System.Uri object for the specified action within the controller.

Example

C#
var uri = uriResolver.Action("Index", "Home", new { id = 42 });
// Result could be something like: "http://example.com/Home/Index?id=42"

IUriResolver.Content(string) Method

Generates an absolute URI for a given content path. This method is useful for creating links to static resources stored within the application, such as images, CSS files, and JavaScript files. It supports: - Application root-relative paths using the '' symbol (e.g., "/images/logo.png") - Route template constants from Path class (e.g., Authorize) - Regular relative paths

C#
System.Uri Content(string path);

Parameters

path System.String

The path to the content. This can be: - A virtual path (e.g., "/images/logo.png") indicating the application root - A route template constant (e.g., Path.Authorize = "[route

?/connect/authorize]") - A relative path from the current executing location

Returns

System.Uri
An absolute URI as a System.Uri object for the specified content path.

Example

C#
// Static content
var uri1 = uriResolver.Content("~/content/site.css");
// Result: "https://example.com/content/site.css"

// Route template constant (uses configured or default path)
var uri2 = uriResolver.Content(Path.Authorize);
// Result: "https://example.com/connect/authorize"