We can do it in two ways. The first way to create a route using convention routing is as follows:
- We add services.AddMvc() to ConfigureServices:
app.AddMvc();
- We add app.UseMvc() to configure the route definitions:
app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); });
The second way to create a route using convention routing is as follows:
- We add services.AddMvc() to ConfigureServices:
app.AddMvc();
- Now, it's time to add app.UseMvc() method call inside Configure() method:
app.UseMvc();
- We add attribute routing to the controller and/or action:
[Route("api/[controller]")] public class ValuesController : Controller