.NET Tools How-To's

Work with ASP.NET Core route templates in ReSharper and Rider

Routing is at the core of ASP.NET development. In the latest 2021.1 EAP builds, ReSharper and Rider now offer some excellent new functionality to work with routes and route templates in ASP.NET. Let’s take a look what the .NET tools can do for you.

Route completion

Sometimes, it’s the little things that are the most helpful. Once you’ve declared a parameter in an action method, ReSharper or Rider inserts the route template of your choice.

Type the opening bracket {, then select the parameter to fill in. This is a great way to define routes quickly and without typos.

Autocomplete route templates

Add/remove route parameters

If a parameter is defined in an action method but not in the route template, you may want to add it to the template as well. You can quickly add and remove routing parameters by using Alt+Enter.

This works in reverse too. If a parameter is defined in a route template but not the action method, Alt+Enter adds it in as a parameter of the method.

Add route parameter to template

Rename refactoring parameters in route templates

As you might have expected, ReSharper and Rider offer rename refactoring for route parameters too. ReSharper and Rider users will love that standard rename refactoring is available for even the most complex route patterns and placeholder definitions. Notice that the parameter is renamed everywhere, not just the action method and parameter template (Alt+Enter).

Rename refactor works for route templates

Parameter type checks

ReSharper and Rider indicate the availability of type constraints that match an action method’s parameter type when a constraint has not yet been applied to a path template. Add the type constraint by using Alt+Enter.

In addition to the type, route templates can provide validation such as length, required, range, a regular expression, or a minimum or maximum value. Type a colon : after the type, and select a validation and select a validation option from the list that ReSharper or Rider provides.

Rider does route parameter type checks and validation

Extract to controller’s route template

Sometimes, routes defined on action methods work better at the controller level, as routes can be defined for all actions in the current controller. When this happens, Rider notifies you by displaying an intention indicator. Press Alt+Enter and extract the route template to the controller. You can then add route information to individual action methods.

Extract route templates to controller


Routing is an important aspect of ASP.NET web development. ReSharper and Rider have many great new features for building and managing routes in all ASP.NET project types.

Additionally, Rider has several quick fixes and helpers to keep your routes in order. Download Rider 2021.1 EAP and let us know if route building in ASP.NET is easier than ever before.

image description

Discover more