Skip to content

ConfigurableRouteConvention Class

A convention that resolves tokenized route templates using configuration values, supporting fallback values with the syntax: [route

?FallbackValue].

C#
public class ConfigurableRouteConvention : Microsoft.AspNetCore.Mvc.ApplicationModels.IApplicationModelConvention

Inheritance System.Object → ConfigurableRouteConvention

Implements Microsoft.AspNetCore.Mvc.ApplicationModels.IApplicationModelConvention

Constructors

ConfigurableRouteConvention(string, IConfigurationSection) Constructor

Initializes a new instance of the ConfigurableRouteConvention class.

C#
public ConfigurableRouteConvention(string prefix="route", Microsoft.Extensions.Configuration.IConfigurationSection? configSection=null);

Parameters

prefix System.String

The token prefix to recognize in route templates. Defaults to "route".

configSection Microsoft.Extensions.Configuration.IConfigurationSection

The configuration section to use for token resolution.

Remarks

Tokens must follow the format: [route

] or [route
?FallbackValue].

Methods

ConfigurableRouteConvention.Apply(ApplicationModel) Method

Applies the route token resolution to all controllers and actions in the application model.

C#
public void Apply(Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModel application);

Parameters

application Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModel

The application model to apply the convention to.

Implements Apply(ApplicationModel)

Exceptions

System.InvalidOperationException
Thrown if a route token is not found in the configuration.

ConfigurableRouteConvention.Apply(SelectorModel) Method

Applies token replacement to a single selector's route template.

C#
public void Apply(Microsoft.AspNetCore.Mvc.ApplicationModels.SelectorModel selector);

Parameters

selector Microsoft.AspNetCore.Mvc.ApplicationModels.SelectorModel

The Microsoft.AspNetCore.Mvc.ApplicationModels.SelectorModel whose route template may contain tokens.

ConfigurableRouteConvention.Resolve(string) Method

Replaces all recognized route tokens in the format [route

?Fallback] with their resolved values.

C#
public string Resolve(string template);

Parameters

template System.String

The original template string.

Returns

System.String
The resolved route template string.

Exceptions

System.InvalidOperationException
Thrown if a token cannot be resolved and no fallback is provided.