Home NewsX Manged Modules and Custom Modules in IIS

Manged Modules and Custom Modules in IIS

by info.odysseyx@gmail.com
0 comment 20 views


index:

  1. Modules in IIS
  2. Types of modules
  3. Integration within IIS architecture and pipeline
  4. Custom modules and creation
  5. Interrupting the receiving request
  6. Features of custom modules
  7. Advantages of using custom modules
  8. summation

Modules in IIS


Modules in Internet Information Services (IIS) are individual functions that the server uses to process requests. Modules
A component that handles specific tasks during the processing of a web request. These tasks can range from authentication and logging to compression and caching. Modules are essential to how IIS manages and processes requests, allowing for a modular and customizable approach to web server functionality. These features are designed to handle specific tasks such as authentication, caching, and logging.

There are two types of modules available:

  • Core modules: Built into IIS and handles core functionality such as authentication, compression, and logging.
  • Managed modules: Written in managed code (e.g. .NET) and provide additional functionality such as session state management and URL authentication.

Modules can inspect, modify, or take action on requests and responses. They participate in the request processing pipeline to ensure that tasks such as user authentication, data compression, and request filtering are handled efficiently.

Integration within IIS architecture and pipeline

Let’s take a look at the IIS pipeline mode.

Integration within IIS architecture and pipeline

Custom modules are integrated into the IIS request processing pipeline, which follows these steps: By subscribing to events such as `BeginRequest`, custom modules can intercept and process requests at various points in this pipeline.

meenakshiBalekar_4-1725021972726.png

On the left are the steps that will be part of the request lifecycle. There are various steps like authentication, authorization, execution handler, compression, and on the right are modules like base and window that will be subscribed to various steps.

Modules subscribe to various stages.

Modules are loaded into the IIS pipeline and participate in request processing. Modules can inspect, modify, or act on requests and responses. For example, an authentication module can verify user credentials before allowing access to resources, and a compression module can compress response data before sending it to the client.

So how does it work?

Let’s say you have an ASP.NET Framework application hosted on IIS. You have enabled Windows Authentication on this website.

meenakshiBalekar_5-1725021972728.png

So here, a request to my website goes through the standard IIS pipeline, but since I have Windows Authentication enabled, when it gets to the authentication stage in the pipeline, you can see that it checks to see if there are any modules subscribed to this stage. If it identifies that Windows Authentication is enabled, it intercepts the request, performs Windows Authentication, and then processes the request.

To see what this looks like, you can do a FREB trace and see the Windows Authentication module running during the authentication phase.

meenakshiBalekar_9-1725022361743.png

There are also modules that are not yet subscribed and therefore do not perform any activity.

This is how modules make IIS a flexible and powerful web server, allowing administrators and developers to tailor its behavior to meet specific application needs. But how do you achieve this flexibility?

For this purpose, we can customize the module according to our needs.

Custom Modules

You can create custom modules to extend IIS functionality. These modules can be written in native code (C/C++) or managed code (C#, VB.NET). Custom modules allow for tailored solutions to specific needs, such as custom logging, authentication, or request processing.

Writing and Adding Custom Modules in IIS

Creating a custom module for IIS involves writing managed or native code that hooks into the IIS request processing pipeline. Here’s a step-by-step guide.

Step 1: Create a new class library project

Open Visual Studio and create a new Class Library project.

Specify a project name (e.g. RemoveHeadersModule).

Step 2: Implementing the IHttpModule interface

Add a new class to your project (e.g. RemoveHeadersModule.cs).

Implement the IHttpModule interface in this class.

public class CustomModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(OnBeginRequest);
//this is where you can add your logic to modify the request
}
private void OnBeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
context.Response.Write("Custom Module Executed!");
}
public void Dispose() 
{ }
}

For native code, create ISAPI extensions or filters using C++.

Step 3: Register the module

  1. Open the web.config file.
  2. To register a custom module, add the following configuration:

  
    
      
    
  


Step 4: Deploy the module

Build the project to generate the DLL.

Copy the DLL bin This is the directory of the web application.

Check yours web.config Updated with module registration.

Interrupting the receiving request

Custom modules can modify the behavior of incoming requests by inspecting and modifying request headers, redirecting requests, or even generating responses. For example, a module might be designed to:

  • Log request details.
  • Apply custom authentication or authorization logic.
  • Modify the response header.

This can also be seen in the FREB log.

I created a class library name like this: I have integrated RemoveHeadersModule with my IIS hosted application. When I do a FREB trace, I can see the same request being executed like this:

meenakshiBalekar_7-1725021972733.png

This will allow you to modify your request according to your requirements.

Features of custom modules

Custom modules can be used for a variety of purposes.

  • Authentication and Authorization
  • Request and response filtering
  • URL Rewrite
  • Custom Logging
  • Load Balancing

Advantages of using custom modules

Custom modules offer several benefits:

  • Flexibility: Customize request processing to fit your specific needs.
  • Extensibility: Enhance IIS functionality without modifying core server code.
  • Performance: Improve request processing efficiency through specialized logic.

summation

In conclusion, the flexibility and performance of IIS as a web server are significantly enhanced by using both native and custom modules. These modules provide a highly customizable and efficient way to process web requests, giving you the ability to tailor the behavior of the server to meet the specific needs of your application. In particular, custom modules provide the opportunity to extend IIS functionality in a targeted way, such as improving the authentication process, filtering requests and responses, and rewriting URLs.

By leveraging the capabilities of custom modules, administrators and developers can ensure that their web servers are optimized for performance, security, and stability.





Source link

You may also like

Leave a Comment

Our Company

Welcome to OdysseyX, your one-stop destination for the latest news and opportunities across various domains.

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Laest News

@2024 – All Right Reserved. Designed and Developed by OdysseyX