Last post Feb 15, 2012 04:28 AM by mrgruby
Feb 10, 2012 03:11 AM|mrgruby|LINK
I've created a small Class Library, with a HttpModule that uses a filter to add some html to every requested page served by IIS7.
I tested it first by registering the module in the web.config in a test web site, and it works as it should, but only in that one application.
I generated a dll, and created a strong named assembly.
I need to somehow add this assembly as a module in IIS on a server level, so that it works for all requests, on all applications, and for non-asp.net content as well.
So far, I have tried adding the .dll as a native module. This doesn't work. It's on the list of native modules, but it doesn't work.
I have installed the .dll in the GAC.
Reading on, it seems I have to add the assembly as a managed module, and then choose it in the dropdown list under "add managed module" in IIS.
For this, I tried using the commandline tool appcmd, writing: "add module /name: string /type: string /preCondition: string"
I've had no success doing this, since I can't figure out what to set as type and precondition.
As I have read, the modules registered in IIS should work for all applications in all sites, and all requests.
The point is to avoid having to register the module in every applications web.config file.
Feb 15, 2012 04:28 AM|mrgruby|LINK
I am now able to run the module on every request.
The steps involved to make it work is:
1. Write the code you want to run on every request, as a .net 3.5 Class Library.
2. Compile it as a strong-named assembly.
3. Install the assembly in the GAC.
4. In IIS7 manager, select the server name in connections, click Modules, click "Add managed module" in actions.
5. write a name for the module and choose your newly installed assembly in the type dropdown.
6. Make sure the site uses an application pool running in integrated mode.
Ofcourse, it's not always a good idea to let all code run on all requests, so you may need to filter some of the requested files.
One question remains though!
There are now two GAC's, Microsoft.NET for .net 4.0, and Windows GAC for pre .net 4.0.
Because I created my assembly in .net 3.5, it was installed in Windows GAC, and therefore it was avalable in the type dropdown in IIS manager.
When I created my assembly in .net 4.0, it was installed in the Microsoft.NET GAC, and as a result, it was NOT avalablein the type dropdown in IIS manager.
The question is: How do you add a .net 4.0 assembly as a managed module in IIS7, and have it run like my 3.5 managed module?
This must be possible, right?