Nov 02

Failed requests tracing in IIS 7

Posted in ASP.NET      Comments Off on Failed requests tracing in IIS 7

In these last days I”ve been rather busy porting my old ASP.NET 2.0 samples to the new version of the platform. Until now, I believe that the greatest things that we will have in the new version are IIS related! Today I was playing with the Failed Request Tracing service of IIS 7. It”s a really cool new service which will really help you if you like to use tracing to see what”s going on your pages or site. There”s already a good article on how to enable and configure this new service, so I won”t really go into it here.

What I”ve also found is that there is a new health monitoring provider which will automatically convert an event into a tracing message that is going to be sent to this new IIS service. I”m talking about the IisTraceWebEventProvider class. Using it is really simple: you just need to add it to the providers section in your config file and create a rule that uses it. Here”s what I did to test this new health monitoring provider:

<healthMonitoring enabled=”true”>
    <add name=”My rule” eventName=”All Errors” provider=”IISProvider” profile=”Critical” />
    <add name=”IISProvider” type=”System.Web.Management.IisTraceWebEventProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” />
<authentication mode=”Windows” />

What I”m saying here is that I”ve got a new provider (which I”ve named IISProvider) and I”ve create a new rule (called My rule) which  ties the “All Errors” events (events of type WebBaseErrorEvent) to IISProvider provider (you can think of rules as being the “glue” that associates an event with a provider – btw, you can associate an even with several providers by adding a new rule for each provider).

Then, to see if everything was working out smoothly, I”ve set up a page which generates an error. The simplest thing I could think of was this:

<%@ Page Language=”C#” %>
<%@ Import namespace=”System.Reflection”%>
<%@ Import namespace=”System.Web.Management”%>
<%@ Import Namespace=”LivroASP” %>
<script runat=”server”>
    void ProcessClick( object sender, EventArgs args )

        Int32 a = 0;
        Int32 b = 10/a; //generates exception
<head id=”Head1″ runat=”server”>
    <title>Untitled Page</title>
    <form id=”form1″ runat=”server”>
        <h3>Utilização de um evento personalizado</h3>   
        <small>Esta página demonstra a utilização de um evento personalizado (necessário remover comentários da secção
        healthMonitoring do web.config</small><br />
        <asp:Button runat=”server” id=”bt” Text=”Evento” OnClick=”ProcessClick” />


If you run this page (and you have enabled Failed Request Tracing in IIS), then you should see the a warning entry with the error exception on the log file for the Failed Request Tracing service (notice that if you disable Health Monitoring,you”ll still get the MODULE_SET_RESPONSE_ERROR_STATUS entry,but you won”t get the RequestErrorEvent entry associated with theHealth Monitoring service).