IIS7 - post #13 - Failed Request Tracing (FREB) and my own version of FREB Tree Control (v0.01)

Tags: IIS

It has been a while since I geeked on IIS7.  I was checking out Mike Volodarsky blog for the latest and greatest on IIS7.   There was an article on FREB (Failed Request Event Buffer).  This feature has been politely renamed to Failed Request Tracing, I have a feeling FREB will stick around.   Mike pointed to an updated FREB.XSL.  This helps display requests in a more friendly format than using Notepad.  Here is the article by Bill Staples about this. Making Failed Request Tracing More Approachable  

I like viewing things in TreeControls so lets start a FREB Tree Control.  :)  This version displays the FailedReqLogFiles sub-folders with associating files in a TreeView.  You can click on the file and have it display in IE.  This version only works in IE.  Firefox pops up a message about not knowing how to display an XML file.  I'm sure there is a Firefox guru reading this post that knows how to resolve that. :)   Here is the code for the tree control.  You can download the code here.

Default.aspx
------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Failed Request Tracing Tree Control</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>Failed Request Tracing Tree Control by Steve Schofield</h1>
        <table width="100%">
            <tr>
                <td style='width:25%' valign='top'>
                    &nbsp;<asp:TreeView ID="TreeView1" runat="server" ExpandDepth=1>
                    </asp:TreeView>
                   
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>


Default.aspx.vb
------------

Imports System.IO

Partial Class _Default
    Inherits System.Web.UI.Page

    Private Const LogRoot = "C:\inetpub\logs\FailedReqLogFiles"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'On the first page visit, populate the photo tree and select the root node
        If Not Page.IsPostBack Then
            PopulateTree()
        End If
    End Sub

    Private Sub PopulateTree()
        'Populate the tree based on the subfolders of the specified LogRoot
        Dim rootFolder As New DirectoryInfo(LogRoot)
        Dim root As TreeNode = AddFoldersToTreeView(rootFolder, Nothing)

        'Add the root to the TreeView
        TreeView1.Nodes.Add(root)
    End Sub

    Private Function AddFoldersToTreeView(ByVal folder As DirectoryInfo, ByVal parentNode As TreeNode) As TreeNode
        'Add the TreeNode, displaying the folder's name and storing the full path to the folder as the value...
        Dim virtualFolderPath As String

        If parentNode Is Nothing Then
            virtualFolderPath = LogRoot
        Else
            virtualFolderPath = parentNode.Value & folder.Name & "/"
        End If

        Dim node As New TreeNode(folder.Name, virtualFolderPath)
        Dim subFolders As DirectoryInfo() = folder.GetDirectories()

        For Each subFolder As DirectoryInfo In subFolders
            Dim files As TreeNode = AddFilesToTreeView(subFolder)
            node.ChildNodes.Add(files)
        Next
        Return node     'Return the new TreeNode
    End Function

    Private Function AddFilesToTreeView(ByVal folder As DirectoryInfo) As TreeNode
        'Add the TreeNode, displaying the folder's name and storing the full path to the folder as the value...
        Dim files As New TreeNode(folder.Name, folder.Name.ToString())
        For Each file As FileInfo In folder.GetFiles()
            Dim child As New System.Web.UI.WebControls.TreeNode
            child.Value = "<a href='" & file.FullName.ToString & "' target='_blank'>" & file.FullName.ToString & "</a>"
            files.ChildNodes.Add(child)
        Next
        Return files     'Return the new TreeNode
    End Function
End Class

Here is an image of this running on my Longhorn server.

Enjoy,

Steve Schofield
Microsoft MVP - IIS