Server Side Programming Articles

Page 683 of 2109

How to add custom message handlers to the pipeline in Asp.Net webAPI C#?

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

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 More

How to set a property having different datatype with a string value using reflection in C#?

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

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 More

How do we specify MIME type in Asp.Net WebAPI C#?

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

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 More

What is the use of the Configure() method of startup class in C# Asp.net Core?

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

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 More

What is the use of "Map" extension while adding middleware to C# ASP.NET Core pipeline?

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

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 More

How to specify service lifetime for register service that added as a dependency C# Asp.net Core?

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

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 More

How C# ASP.NET Core Middleware is different from HttpModule?

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

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

What is the AddSingleton vs AddScoped vs Add Transient C# Asp.net Core?

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

Dependency injection in ASP.NET Core provides three service lifetime options that determine when service instances are created and disposed. These service lifetimes − AddSingleton, AddScoped, and AddTransient − control the lifecycle of your registered services. Understanding these lifetimes is crucial for proper memory management and ensuring your application behaves correctly across different requests and users. Syntax All three methods follow the same registration syntax in the ConfigureServices method − public void ConfigureServices(IServiceCollection services) { services.AddSingleton(); services.AddScoped(); services.AddTransient(); } ...

Read More

How to find the Number of CPU Cores in C#?

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

Finding the number of CPU cores in C# involves understanding different types of processor information. There are several ways to get processor details − Physical processors − The actual number of CPU sockets CPU cores − The number of physical processing units Logical processors − The number of threads the CPU can handle simultaneously These values can differ significantly. For example, a machine with 2 dual-core hyper-threading-enabled processors has 2 physical processors, 4 cores, and 8 logical processors. CPU Architecture Example Physical CPU 1 ...

Read More

How to rethrow InnerException without losing stack trace in C#?

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

In C#, rethrowing exceptions while preserving the complete stack trace is crucial for effective debugging. When handling exceptions, you have several options for rethrowing that affect how much debugging information is preserved. The key difference lies between using throw; (which preserves the full stack trace) versus throw ex; (which resets the stack trace to the current location). Additionally, when dealing with InnerException, you need special techniques to maintain the complete exception chain. Syntax Following is the syntax for rethrowing an exception without losing stack trace − try { // code that might ...

Read More
Showing 6821–6830 of 21,090 articles
« Prev 1 681 682 683 684 685 2109 Next »
Advertisements