How to configure C# ASP.NET WebAPI in web.configure file?


No we cannot configure WEB API in web.configure file.

Web API supports code based configuration. It cannot be configured in web.config file.

We can configure WEB API, to customize the behaviour of Web Api hosting Infrastructure and component such as

  • Routes

  • Formatters

  • Filters

  • Dependency Resolver

  • Message Handlers

  • ParameterBindingRules

  • Properties

  • Services

Routes − The public methods of the controller are called action methods or simply actions.

When the Web API framework receives a request, it routes the request to an action. To determine which action to invoke, the framework uses a routing table

routes.MapHttpRoute(
   name: "API Default",
   routeTemplate: "api/{controller}/{id}",
   defaults: new { id = RouteParameter.Optional }
);

Formatters

ASP.NET Core MVC supports data exchange in Web APIs using input and output formatters. Input formatters are used by Model Binding. Output formatters are used to format responses.

Use a custom formatter to add support for a content type that isn't handled by the built-in formatters.

Filters − Filters can be used to provide cross-cutting features such as logging, exception handling, performance measurement, authentication and authorization.

Dependency Resolver − Web API defines the IDependencyResolver interface for resolving dependencies.

Message Handlers − Message handlers in Web API provides a process, edit, or decline an incoming request before it reaches the HttpControllerDispatcher.

ParameterBindingRules −When Web API calls a method on a controller, it must set values for the parameters, a process called binding.

Updated on: 19-Aug-2020

885 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements