I’ve been working on a module for IIS7. I want to intercept requests from a specific browser. This is only in dev, but right now my code looks like this:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace MyNamespace
{
class MyModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(OnPreRequestHandlerExecute);
}
#endregion
public void OnPreRequestHandlerExecute(Object source, EventArgs e)
{
HttpApplication app = (HttpApplication)source;
HttpRequest request = app.Context.Request;
string useragent = "AGENT: " + request.Headers["User-Agent"];
throw new HttpException(403, useragent);
// stuff here
}
}
}
I want to test this, but despite reading NUMEROUS articles on adding it to IIS7, I can’t seem to get it working.
Examples:
http://learn.iis.net/page.aspx/366/developing-iis-70-modules-and-handlers-with-the-net-framework/
http://learn.iis.net/page.aspx/269/how-to-create-a-simple-iis-manager-module/
I’ve got the module strongly named, signed, you name it. I can’t seem to get it to show up under Managed Modules for IIS.
If someone who has experience in this area could point me in the right direction I would greatly appreciate it! The code is very incomplete and I don’t expect it to be perfect, but just to get it working under IIS7 right now would be a huge step forward.
Thanks!
You can simply drop the MyNameSpace.dll file in the bin folder, and then reference it like this in the section of the web.config: