ASP.NET Podcast Show #98 - Building an IIS7 HttpModule - More Wally - Wallace B. McClure
in

MoreWally.com

Giving people what they want, More Wally. This is the technical and personal blog site of
Wallace B. (Wally) McClure.

This Blog

Syndication

News

Please goy buy 3-4 copies of my book on MonoTouch titled "Professional Android Programming with Mono for Android for .NET/C# Developers." They make great gifts all year round. Plus, I get about $.25 when you buy a copy.

Technical Sites

More Wally - Wallace B. McClure

This blog will have all kinds of posts about Wally McClure. In it, there will be tons of .NET and computer programming posts as well as Wally's views on life in general. As you might guess, this site and blog help you get More Wally in your life. What more could anyone want? iPhone, Android, MonoTouch, MonoDroid, Mobile, HTML5, .NET, ADO.NET, ASP.NET, AJAX, jQuery, jQuery Mobile, ASP.NET AJAX, and Windows Azure............follow me on twitter at Wally

ASP.NET Podcast Show #98 - Building an IIS7 HttpModule

Original URL: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2007/08/01/asp-net-podcast-show-98-building-an-iis7-http-module.aspx 

Subscribe <-- What you really want.

Download WMV

Download M4V - IPod and Zune

Download MP3 - Audio only.

Show notes:

  • Windows Server 2008.
    • Visual C# Express.
    • Visual Web Developer Express.
  • Class Library in C#.
    • IHttpModule Interface.
    • Init, Dispose.
    • Begin/End Request Events.
    • Other Server Events.
    • Messaging?
  • Web.Config.
  • Example.
  • IIS Manager.
  • WebDev Server vs. IIS7 Service.
  • Error and how to fix it.

 Source Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Messaging;

namespace IISWatcher
{
    public class WatchRequests : IHttpModule
    {
        public void Init(System.Web.HttpApplication app)
        {
            app.BeginRequest += new EventHandler(app_BeginRequest);
            app.EndRequest += new EventHandler(app_EndRequest);
        }
        void app_EndRequest(object sender, EventArgs e)
        {
            //HttpApplication app = (HttpApplication)sender;
        }
        void app_BeginRequest(object sender, EventArgs e)
        {
            string strReturn = "\r\n";
            HttpApplication app = (HttpApplication)sender;
            string strAddress = app.Request.UserHostAddress;
            string strUrl = app.Request.Url.AbsoluteUri;
            string strQS = app.Request.QueryString.ToString();
            RequestInfo ri = new RequestInfo();
            System.Diagnostics.EventLog.WriteEntry("HttpModule",
                "IpAddress: " + strAddress + strReturn + "URL:" + strUrl);
            System.Messaging.MessageQueue msq = new MessageQueue(@".\private$\HttpModuleQueue");
            ri.AbsoluteUri = strUrl;
            ri.IPAddress = strAddress;
            ri.QueryString = strQS;
            msq.Send(ri);
        }

        public void Dispose()
        {
        }
    }
    public class RequestInfo
    {
        public string IPAddress;
        public string AbsoluteUri;
        public string QueryString;
    }
}

Web.config for IIS7:

<configuration>
...................
    <system.webServer>
        <modules>
            <add type="IISWatcher.WatchRequests" name="IIS7RequestWatcher"/>
        </modules>
    </system.webServer>
</configuration>

Comments

No Comments
2006 - Wallace B. McClure
Powered by Community Server (Non-Commercial Edition), by Telligent Systems