Manged Modules and Custom Modules in IIS by info.odysseyx@gmail.com August 30, 2024 written by info.odysseyx@gmail.com August 30, 2024 0 comment 20 views 20 index: Modules in IIS Types of modules Integration within IIS architecture and pipeline Custom modules and creation Interrupting the receiving request Features of custom modules Advantages of using custom modules 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. 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. 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. 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 Open the web.config file. 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: 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 Share 0 FacebookTwitterPinterestEmail info.odysseyx@gmail.com previous post New on Azure Marketplace: August 18-24, 2024 next post Learn Live: Certificação GitHub Foundations You may also like Biden Battered Over AI Diffusion Policy January 14, 2025 The best thing about CES 2025 January 13, 2025 Meta Scrap fact-checker, eases content restrictions January 8, 2025 2025 Cyber Security Predictions Influenced by AI January 7, 2025 7 Disturbing Tech Trends of 2024 December 19, 2024 AI on phones fails to impress Apple, Samsung users: Survey December 18, 2024 Leave a Comment Cancel Reply Save my name, email, and website in this browser for the next time I comment.