Monday, March 12, 2018

The Lifecycle of an ASP.NET Web API

In this blog, we will discuss the life cycle of an ASP.NET Web API message, which travels from Server to client.

ASP.NET Web API is a .net framework which is used to build HTTP based Restful service and Web API is a lightweight service and supports broad range of clients (mobile app, web apps etc.) and it allows multiple devices to access data via API with any configuration settings.

Steps To Create ASP.NET Web API

Web API Request/Repose Processing Pipeline:

Life-cycle of WEB API

Http Server:  Gets request from host (IIS or Managed application).

Message Handler/Delegating Handler:  it is used before routing the request and these message handler arranged module in HTTP pipeline and each receives request and does some work and pass to next message handler in pipeline. Message handler can send response back without passing to next handler and you can use Message Handler to validate request and based on this, create response also.

Routing Dispatcher: Parse route information and depending on route dispatch request.

Controller Dispatcher : it creates instance of Web API Controller based on matched route

Authorization Filter: after controller instantiate, request pass through the authorization filters, if authorization filter configured in pipeline and it checks authorization of request, in case of fail, send back response directly.


Model Binding: controller calls web API Controller method, before that it set method parameters value, this is called model binding. We can defined own custom model binding to set action parameter value (asp.net web api parameter binding)

Action Filter: After Model Binding, if action is attributed with action filter, action filter will be invoked and it is invoked two times, One before action is executed and 2nd time, after action executed


Controller Action: controller action execute its code and on depend of result, it created HTTP Response.


Exception Handler: if any unhand-led exception is occurred, exception filer is execute, it can have common exception handling logic.

No comments:

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...