How to use attribute routing in ASP.NET Core

The routing middleware in ASP.Net Main is adept at mapping incoming requests to the respective route handlers. You can set up routing in ASP.Net Main in two distinctive techniques: attribute-based mostly routing and convention-based mostly routing.

Not like convention-based mostly routing, in which the routing information is specified at a single locale, attribute routing permits you to implement routing by decorating your action solutions with attributes. This report presents a discussion of how we can work with attribute-based mostly routing in ASP.Net Main MVC.

To work with the code illustrations supplied in this report, you should really have Visible Studio 2019 installed in your process. If you never already have a duplicate, you can download Visible Studio 2019 listed here. 

Produce an ASP.Net Main 3.one MVC task in Visible Studio 2019

Initial off, let us develop an ASP.Net Main task in Visible Studio 2019. Assuming Visible Studio 2019 is installed in your process, abide by the ways outlined under to develop a new ASP.Net Main task in Visible Studio.

  1. Launch the Visible Studio IDE.
  2. Simply click on “Create new task.”
  3. In the “Create new project” window, pick “ASP.Net Main Internet Application” from the checklist of templates displayed.
  4. Simply click Next.
  5. In the “Configure your new project” window, specify the name and locale for the new task.
  6. Optionally verify the “Place solution and task in the same directory” verify box, based on your tastes.
  7. Simply click Produce.
  8. In the “Create a New ASP.Net Main Internet Application” window shown subsequent, pick .Net Main as the runtime and ASP.Net Main 3.one (or later) from the fall-down checklist at the prime.
  9. Decide on “Web Software (Model-Check out-Controller)” as the task template to develop a new ASP.Net Main MVC application. 
  10. Be certain that the verify containers “Enable Docker Support” and “Configure for HTTPS” are unchecked as we won’t be using people attributes listed here.
  11. Be certain that Authentication is set to “No Authentication” as we won’t be using authentication possibly.
  12. Simply click Produce.

Adhering to these ways will develop a new ASP.Net Main MVC task in Visible Studio 2019. We’ll use this task in the sections under to illustrate how we can work with attribute routing in ASP.Net Main 3.one.

Produce a controller class in ASP.Net Main MVC

Produce a new controller named DefaultController and change the default supply code of the DefaultController with the pursuing code:

Copyright © 2020 IDG Communications, Inc.

Next Post

2020 Volkswagen Jetta review: Spacious and mature, but hardly exciting

The Jetta’s styling is clear and basic. Craig Cole/Roadshow Vehicles don’t get considerably more middle-of-the-highway than the Volkswagen Jetta. Experienced seeking and spacious within, it’s as reasonable as a pair of sweatpants, if not really as relaxed.  Like Great genuine-world gasoline financial system Roomy backseat and trunk Reliable infotainment procedure […]