ASP.NET Podcast

ASP.NET Podcast is geared towards the Microsoft .NET Framework and ASP.NET.
The podcast is run by Wally and Paul.
Welcome to ASP.NET Podcast Sign in | Join | Help
in Search

ASP.NET Podcast

The ASP.NET Podcast features, technical talks, interviews, news, reviews, and Wallyisms. Wallace B. (Wally) McClure and Paul Glavich are your hosts.

ASP.NET Podcast Show #98 - Building an IIS7 Http Module (video and audio)

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>
 


Published Wednesday, August 01, 2007 9:15 PM by admin
Anonymous comments are disabled
Powered by Community Server, by Telligent Systems