Tuesday, March 13, 2012

Install an HttpModule in IIS 7.5 on Server 2008 R2

Mostly for my own notes for when I next need to do this again. Assumes that the HttpModule has already been compiled and that you have the DLL.

Copy the DLL to the server and put in any folder.

Install the module into the GAC

  1. Right click on a command window and select "Run as administrator"
  2. At the command prompt type "explorer c:\windows\assembly" without the quotes.
  3. Find the folder that you copied the DLL to and while holding down the control key right click this folder and select "Open in a new window".
  4. Drag the HttpModule DLL from the new window and drop it into the c:\windows\assembly window.
  5. The HttpModule is now installed in the GAC.

Add the module to IIS 7.5

(This assumes a .NET 2.0 module (there's a good reason why it's .NET 2.0 and not 4))

  1. Open IIS and navigate to root. This is usually the machine name and adding the module here will ensure that it operates on all websites.
  2. In the Features View find the IIS section and double click on Modules.
  3. Click "Add Managed Module"
  4. In the Name field put any name you want.
  5. In the Type dropdown you should find the module that you added to the GAC above. Select this.
  6. Leave the "Invoke only for requests to ASP.NET applications or managed handlers" unchecked.
  7. Click OK and you're done.

This HttpModule will now execute against every request on all web sites.

2 comments:

  1. What is the reason for using a .NET 2.0 vs .NET 4.0 module?

    ReplyDelete
  2. By default IIS 7.5 loads the module with the 2.0 runtime. To load using the 4.0 runtime use the appcmd command line tool with the runtimeVersionv4.0 precondition
    %windir%\system32\inetsrv\appcmd add module /name:MyModule /type:MyAssembly.MyModule, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxx /preCondition:runtimeVersionv4.0

    ReplyDelete