Server Side Programming Articles

Page 682 of 2109

How can we create a LOG filter for Logging purposes in C# ASP.NET WebAPI?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 1K+ Views

Action filters in C# ASP.NET Web API are used to add extra logic before or after action methods execution. The OnActionExecuting and OnActionExecuted methods allow you to inject custom logic at specific points in the request pipeline, making them perfect for logging purposes. A LOG filter helps track API method calls, execution times, and other diagnostic information. This is particularly useful for debugging, performance monitoring, and audit trails in production applications. Syntax Following is the syntax for creating a custom action filter by inheriting from ActionFilterAttribute − public class LogAttribute : ActionFilterAttribute { ...

Read More

What is Shallow Copy and how it is different from Deep Copy in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 1K+ Views

A shallow copy creates a new object but copies only the reference values from the original object. When the copied object contains reference types, both the original and copied objects point to the same memory locations for those inner objects. A deep copy creates a completely independent copy of an object, including all nested objects. Changes to one object do not affect the other since they occupy separate memory spaces. Shallow Copy vs Deep Copy Shallow Copy ...

Read More

How to sort a list of complex types using Comparison delegate in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 656 Views

Sorting a list of complex types in C# can be achieved using the Comparison delegate with the Sort() method. The List.Sort() method has an overload that accepts a Comparison delegate, allowing you to define custom sorting logic for complex objects. The Comparison delegate represents a method that compares two objects of the same type and returns an integer indicating their relative order. Syntax Following is the syntax for the Sort() method using a Comparison delegate − public void Sort(Comparison comparison) The comparison delegate signature is − public delegate int Comparison(T x, ...

Read More

How to write retry logic in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 1K+ Views

Retry logic is implemented to handle transient failures that may resolve themselves after a brief delay. This pattern is essential when working with network operations, database connections, or external APIs that may temporarily fail due to network issues, service overload, or temporary unavailability. It's important to log all connectivity failures that cause a retry so that underlying problems with the application, services, or resources can be identified. Implement retry logic only where you have the full context of a failing operation and when the operation is idempotent (safe to repeat). Syntax Following is the basic syntax for ...

Read More

How to use indexers in C# 8.0?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 169 Views

Indexers in C# allow objects to be accessed like arrays using the square bracket notation. C# 8.0 introduced the index from end operator (^) which provides a more intuitive way to access elements from the end of a collection or sequence. The ^ operator returns an index that is relative to the end of the sequence, making it the most compact and easiest way to access end elements compared to traditional methods like array.Length - 1. Syntax Following is the syntax for defining an indexer in a class − public returnType this[parameterType parameter] { ...

Read More

What is parameter binding in C# ASP.NET WebAPI?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 2K+ Views

Parameter binding in ASP.NET Web API is the process of automatically mapping HTTP request data to controller action method parameters. Web API uses different binding strategies based on the parameter type and can be customized using attributes. Understanding how parameter binding works is essential for building robust Web APIs that can correctly receive and process data from HTTP requests. Default Parameter Binding Rules Web API follows these default rules for parameter binding − Simple types (int, bool, double, string, DateTime, GUID) are bound from the URI (route data or query string) Complex types (custom classes, ...

Read More

What are built-in message handlers in Asp.Net webAPI C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 847 Views

A message handler is a class that receives an HTTP request and returns an HTTP response. Message handlers derive from the abstract HttpMessageHandler class and provide us the opportunity to process, edit, or decline an incoming request before it reaches the HttpControllerDispatcher. Message handlers are executed much earlier in the request processing pipeline, making them ideal for implementing cross-cutting concerns in Web API. They form a chain of classes that process HTTP requests and responses through a pipeline. ASP.NET Web API Message Handler Pipeline ...

Read More

What is Content Negotiation in Asp.Net webAPI C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 3K+ Views

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 More

How to consume Asp.Net WebAPI endpoints from other applications using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 471 Views

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 More

What is the usage of DelegatingHandler in Asp.Net webAPI C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 4K+ Views

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 More
Showing 6811–6820 of 21,090 articles
« Prev 1 680 681 682 683 684 2109 Next »
Advertisements