Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 6 of 2110
What is Content Negotiation in Asp.Net webAPI C#?
Content negotiation in ASP.NET Web API is the process of selecting the best format for the response based on what the client can accept. When a client sends a request, it can specify its preferred response format using HTTP headers, and the server responds accordingly. The primary mechanism for content negotiation relies on several HTTP request headers that communicate the client's preferences to the server. HTTP Headers for Content Negotiation Accept − Specifies which media types are acceptable for the response, such as "application/json, " "application/xml, " or custom media types like "application/vnd.example+xml". Accept-Charset − Indicates ...
Read MoreHow to consume Asp.Net WebAPI endpoints from other applications using C#?
The HttpClient class provides a base class for sending and receiving HTTP requests and responses from URLs. It is a supported async feature of the .NET framework that can process multiple concurrent requests. HttpClient is available in the System.Net.Http namespace and acts as a layer over HttpWebRequest and HttpWebResponse. This article demonstrates how to consume ASP.NET Web API endpoints from external applications using HttpClient. We'll create a Web API with student data and then consume it from a console application. Creating the Web API Student Model First, let's define the Student model − namespace ...
Read MoreWhat is the usage of DelegatingHandler in Asp.Net webAPI C#?
In ASP.NET Web API, a DelegatingHandler is a type of HTTP message handler that forms a chain of handlers to process HTTP requests and responses. Each handler in the chain can perform operations on the request before passing it to the next handler, and then process the response when it comes back up the chain. The DelegatingHandler class allows you to create custom server-side message handlers that can intercept, modify, or handle HTTP requests and responses globally across your Web API application. This is useful for implementing cross-cutting concerns like logging, authentication, caching, or request validation. Syntax ...
Read MoreHow to add custom message handlers to the pipeline in Asp.Net webAPI C#?
To create a custom Server-Side HTTP Message Handler in ASP.NET Web API, we need to create a class that must be derived from the System.Net.Http.DelegatingHandler. Message handlers allow you to intercept HTTP requests and responses, enabling cross-cutting concerns like logging, authentication, caching, or request modification. How Message Handlers Work Message handlers form a pipeline where each handler can process the request before passing it to the next handler, and process the response on its way back. This provides a powerful mechanism for implementing middleware-like functionality in Web API. Message Handler Pipeline ...
Read MoreHow to set a property having different datatype with a string value using reflection in C#?
Reflection in C# allows managed code to examine and manipulate its own metadata, including types, properties, and methods at runtime. This powerful feature enables you to dynamically work with objects without knowing their types at compile time. A common scenario is when you need to set a property of one data type (like double) using a string value at runtime. This can be accomplished using reflection combined with type conversion. Syntax Following is the syntax for getting property information using reflection − PropertyInfo propertyInfo = obj.GetType().GetProperty("PropertyName"); Following is the syntax for setting a ...
Read MoreHow do we specify MIME type in Asp.Net WebAPI C#?
A media type, also called a MIME type, identifies the format of a piece of data. In HTTP, media types describe the format of the message body. A media type consists of two strings, a type and a subtype. For example − text/html image/png application/json When an HTTP message contains an entity-body, the Content-Type header specifies the format of the message body. This tells the receiver how to parse the contents of the message body. When the client sends a request message, it can include an Accept header. The Accept header tells the server which ...
Read MoreWhat is the use of the Configure() method of startup class in C# Asp.net Core?
The Configure() method in ASP.NET Core's Startup class is used to define the application's request pipeline. This method configures how the application handles incoming HTTP requests and outgoing responses using middleware components. The Configure() method is called at runtime after the ConfigureServices() method. It receives an IApplicationBuilder instance from the built-in IoC container, which is used to add middleware to the request pipeline. Syntax Following is the basic syntax of the Configure() method − public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // Configure middleware pipeline } Parameters The ...
Read MoreWhat is the use of "Map" extension while adding middleware to C# ASP.NET Core pipeline?
The Map extension method in ASP.NET Core is used for conditional middleware execution based on the request path. It allows you to branch the middleware pipeline and execute different middleware components for specific URL paths, creating a more organized and efficient request handling system. Middleware components are assembled into an application pipeline to handle requests and responses. Each component can choose whether to pass the request to the next component and perform actions before and after the next component is invoked. Syntax Following is the syntax for using the Map extension method − app.Map("/path", appBuilder ...
Read MoreHow to specify service lifetime for register service that added as a dependency C# Asp.net Core?
The built-in IoC container in ASP.NET Core manages the lifetime of registered services and automatically disposes service instances based on the specified lifetime. Understanding service lifetimes is crucial for proper dependency injection and resource management. The built-in IoC container supports three kinds of lifetimes − Singleton − IoC container will create and share a single instance of a service throughout the application's lifetime. Transient − The IoC container will create a new instance of the specified service type every time you ask for it. Scoped − IoC container will create an instance of the specified service type ...
Read MoreHow C# ASP.NET Core Middleware is different from HttpModule?
In ASP.NET Core, middleware replaces the traditional HttpModules used in classic ASP.NET. While both serve as components that handle HTTP requests and responses, they differ significantly in configuration, execution control, and architecture. Key Differences Overview HttpModules are event-driven components tied to the ASP.NET application lifecycle, while middleware components form a pipeline where each component can handle requests before passing them to the next component in the chain. HttpModules vs Middleware Architecture HttpModules (Classic ASP.NET) Event-driven execution Fixed lifecycle ...
Read More