How do I deploy a managed HTTP Module Site Wide?
Asked Answered
G

3

1

I am developing a manged HTTP Module that will intercept requests to and response from IIS 7. The intercepted messages will be modified based on a set of business rules by a custom filter. The business rules will be stored in a configuration file.

The messages must be intercepted web site wide. This includes any applications or virtual directories that exist as children of the web site. My first attempt at this was to install the HTTP Module assembly in the bin directory of the desired web site.(e.g., C:\inetpub\wwwroot\bin for the Default Web Site).

Once installed I modify the <compilation> element of the web site's web.config file to reference the assembly, like so:

<compilation debug="false">
    <assemblies>
        <add assembly="Company.Product.Module, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" />
    </assemblies>
</compilation>

I also modified the <modules> element of the web site's web.config file.

<system.webServer>
    <modules>
        <add name="MyModule" type="Company.Product.Module.MyModule" />
    </modules>
</system.webServer>

This works well for most content under the web site. However, if there is an application configured under the website (e.g., /wwwroot/MyApplication) I receive the following error when navigating to any resource under that web application:

Could not load file or assembly 'Company.Product.Module, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx' or one of its dependencies. The system cannot find the file specified.

There are two ways I know to get around this:

Option 1:

Copy the HTTP Module assembly and all dependent assemblies to each application's bin directory. I believe that I would also need to duplicate the configuration information from the parent directory. This can become a management nightmare as more and more applications are added to the web site.

Option 2:

Install the HTTP Module assembly and all dependent assemblies in the GAC. This seems to work quite well and avoids a lot of management overhead, however, where does configuration information live? If in the web site's web.config file is this information inherited in all the child applications?

What is the recommend method for deploying a managed HTTP Module site wide? How should configuration be handled so that all configuration is in a central location?

Gutierrez answered 5/11, 2010 at 20:25 Comment(0)
C
3

Deploy the Module

Create a new directory under C:\Inetpub\Wwwroot named Module.
Create a subdirectory named Bin in the newly created Module directory. The resultant path is C:\Inetpub\Wwwroot\Module\Bin.
Copy MyModule.dll from your project's Bin\Debug directory to the C:\Inetpub\Wwwroot\Module\Bin directory.
Follow these steps to mark the new Module directory as a Web application:
    Open Internet Services Manager.
    Right-click the Module directory, and then click Properties.
    On the Directory tab, click Create.
    Click OK to close the Module Properties dialog box.

back to the top Configure the System

In the C:\Inetpub\Wwwroot\Module directory, create a new file named Web.config.
Paste the following text into Web.config:


<configuration>
   <system.web>
      <httpModules>
         <add name="MyModule" type="MyModule.SyncModule, MyModule" />
      </httpModules>
   </system.web>
</configuration>

back to the top Test the Module

In the C:\Inetpub\Wwwroot\Module directory, create a new .aspx file named Test.aspx.
Paste the following text into Test.aspx:


<%@Page Language="VB"%>
<% Response.Write("Hello from Test.aspx.<br>") %>


In the C:\Inetpub\Wwwroot\Module directory, create a Global.asax file.
Paste the following code in Global.asax:


<%@ Import Namespace="MyModule" %>

<script language="VB" runat=server >
Public Sub MyModule_OnMyEvent(src As Object, e As EventArgs)    
  Context.Response.Write("Hello from MyModule_OnMyEvent called in Global.asax.<br>")
End Sub
</script>


Request the Test.aspx page. You should see the following lines of text:


Hello from OnBeginRequest in custom module.
Hello from MyModule_OnMyEvent called in Global.asax.
Hello from Test.aspx.
Chinchy answered 7/4, 2016 at 6:11 Comment(2)
you using interceptor to modify http Request and Response. Request for modify header to pass authorization details like token. and response for you handle response error.Chinchy
implement interceptor blog.angularindepth.com/…Chinchy
G
0

So far you are on right track, can you put your configs in machine.config? to avoid maintaining multiple config?

Googly answered 5/11, 2010 at 20:55 Comment(2)
By on the right track do you mean installation within the GAC, or installation within multiple bin directories?Gutierrez
I am not sure if I will be permitted to make modifications to the machine.config file. Additionally, I would like to be able to support different configurations for different websites. Therefore, I think the ideal location for this information is in web.config. I will need to investigate to see if my configuration settings are properly inherited across all applications within a site.Gutierrez
B
0

You can GAC this dll, but it would break your x-copy deployment story if you already have one in place. If it is ok with you, you can later add this module to configuration in applicationHost.config in location tags: <location path="MySite">, <location path="MySite/MyApp">

Benedictbenedicta answered 6/11, 2010 at 19:53 Comment(1)
I am not sure if I will be permitted to make modifications to the applicationHost.config file. Additionally, I would like to be able to support different configurations for different websites. Therefore, I think the ideal location for this information is in web.config. I will need to investigate to see if my configuration settings are properly inherited across all applications within a site.Gutierrez

© 2022 - 2024 — McMap. All rights reserved.