Defining a new route template

To define route templates in your application, the easiest way is to use the UseMvc method, instead of UseMvcWithDefaultRoute inside the Configure method in your startup class. This method allows you to define the routes you want in your application. For example, in the GiveNTake application, if we want our application to support not only the default route, but also expose the RESTful API with an api prefix (that is, URLs in the form of /api/[controller]/[action]), then this is how we need to change our Configure method:

public void Configure(IApplicationBuilder app, IHostingEnvironment env){    ...    app.UseMvc(routes =>   {       routes           .MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}") .MapRoute(name: ...

Get Hands-On Full-Stack Web Development with ASP.NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.