Service and web page handling in .NET Applications

Official Content
This documentation is valid for:

This article describes the underlying architecture of services and web pages generated by the GeneXus .NET Generator and the reasons for the associated design decisions. 

.NET has basically two models to manage and route APIs and Web page requests in ASP.NET Core as described in Routing to controller actions in ASP.NET Core:

  • Conventional Routing
  • Attribute Routing

Additionally, routing can be managed by a controller mapped to a particular route or by middleware in the pipeline that matches specific URLs of incoming requests and maps them to actions.

In the applications generated by the .NET Generator, Attribute Routing is used for REST services and web pages, and there is a middleware for each type of service. Those middlewares are constructed at app startup using the methods 'MapRoute' and 'MapWhen' (for more details, see the 'Configure' method at the app startup source code). This is known as the convention-based middleware activation model in ASP.NET Core.

Middlewares are assembled in the app pipeline to handle requests and responses; they are chained one after the other so each one will choose whether to pass the request to the next component.

The reasons to choose this mechanism instead of the default routing system with endpoint routing are as follows:

  • Middlewares give more control and high customizability for routing within the application 
  • Less generated code (no metadata attributes are needed in the generated code) since the routing logic is in the middleware 
  • Smaller assembly size.