Skip to content

UriResolver Class

Provides functionality to generate absolute URIs for MVC actions and content within an ASP.NET Core application. This class utilizes ASP.NET Core's Microsoft.AspNetCore.Http.IHttpContextAccessor to access the current HTTP context and Microsoft.AspNetCore.Mvc.Routing.IUrlHelperFactory to create URL helpers for generating URIs.

C#
public class UriResolver : Abblix.Oidc.Server.Mvc.IUriResolver

Inheritance System.Object → UriResolver

Implements IUriResolver

Constructors

UriResolver(IHttpContextAccessor, IUrlHelperFactory, IOptions<MvcOptions>) Constructor

Provides functionality to generate absolute URIs for MVC actions and content within an ASP.NET Core application. This class utilizes ASP.NET Core's Microsoft.AspNetCore.Http.IHttpContextAccessor to access the current HTTP context and Microsoft.AspNetCore.Mvc.Routing.IUrlHelperFactory to create URL helpers for generating URIs.

C#
public UriResolver(Microsoft.AspNetCore.Http.IHttpContextAccessor httpContextAccessor, Microsoft.AspNetCore.Mvc.Routing.IUrlHelperFactory urlHelperFactory, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.MvcOptions> mvcOptions);

Parameters

httpContextAccessor Microsoft.AspNetCore.Http.IHttpContextAccessor

The accessor used to obtain the current Microsoft.AspNetCore.Http.HttpContext, providing context for generating URLs, such as the current request's scheme and host.

urlHelperFactory Microsoft.AspNetCore.Mvc.Routing.IUrlHelperFactory

The factory used to create instances of Microsoft.AspNetCore.Mvc.IUrlHelper, which facilitates the generation of URLs for actions and content.

mvcOptions Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.MvcOptions>

The MVC options used to access registered conventions for route template resolution.

Methods

UriResolver.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#
public 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.

Implements Action(string, string, object)

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"

UriResolver.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#
public 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

Implements Content(string)

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"