Steve Schofield's Blog

October 2006 - Posts

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

    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

     

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • How to have your website access content on a remote content server (network attached storage)

    I had a couple of questions in the http://forums.iis.net forums "how can I have my website access content on a remote server?".   This article is a step by step how-to access content from a remote server.

    Read more....

    http://iislogs.com/articles/23/default.aspx

     

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS7 - post #12

    Here are some very, very good links on IIS7 info from Mike Volodarsky.  Microsoft IIS team guru!.

    David Wang - IIS ultra guru blogger has a new blog.

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • CAPTCHA links

    I was looking at using some type of image verification on my website.   Here are some links with information about 'CAPTCHA'.   Please pass along your tips and tricks when using this technology to stop spam bots, comment spam bots and other automated tools to submit information to your site.

             Stopping Automated Web Robots Visiting ASP/ASP.NET Websites
             http://aspalliance.com/1018_Stopping_Automated_Web_Robots_Visiting_ASPASPNET_Websites

             What is CAPTCHA?
             http://www.captcha.net/

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Impersonating with Windows Security

    This is probably the coolest blog I've come across in a while.  :)

    http://blogs.msdn.com/drnick/archive/2006/10/12/impersonating-with-windows-security.aspx

    tx,

    Steve

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Search engine tips / tricks.

    Every heard the question; How do I get my site to come up in the search engines?  This is a real art-form rather than a silver bullet.  Best thing you can do is have people on other sites link to your site.  It doesn't hurt to submit to http://www.Google.com, http://www.Yahoo.com.  These are free and usually can help generate some traffic.   Additional items is have a robots.txt located in the root of the folder, as many key words as possible in the meta-tag key words.  I'm not sure how effective using keywords in meta-tag headers, it sure can't hurt. :)

    None of these techniques will ensure you top position in Google right away unless you are willing to pay for click option.  This can be rather costly and proceeding with caution is recommended.  A few other options is to have some general based text in the Title of his page because that is usually
    what shows up in a search result.  There are other *free* services that will submit your site to a lot of the search engines but the main ones like Yahoo, Google, MSN, Alta-Vista are good ones to start with.  If you have a few tricks to pass along, let me know.

    The Web Robots Pages
    http://www.robotstxt.org/wc/robots.html

    Webmaster Help Center
    http://www.google.com/support/webmasters/bin/topic.py?topic=8458

    Yahoo Help
    http://help.yahoo.com/help/us/ysearch/?fr=yfp-t-501

    How To Use HTML Meta Tags
    http://searchenginewatch.com/showPage.html?page=2167931

    Tx,

    Steve Schofield
    Microsoft MVP - IIS

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS7 compression info

    I just posted a blog about IIS6 compression.  I was wondering if IIS7 compression was much different.  After some searching, here are some links I found regarding IIS7 compression.  I enabled this successfully on my IISLogs.com server and is working great.  A quick search on Technet doesn't have any IIS7 compression info.

    Migrating an ASP.NET app to IIS 7
    http://www.west-wind.com/WebLog/posts/6075.aspx

    Changes to compression in IIS7
    http://blogs.msdn.com/kjsingla/archive/2006/06/13/Changes-to-compression-in-IIS7.aspx

    IIS Compression by Bernard Cheng
    http://msmvps.com/blogs/bernard/archive/2004/12/01/21614.aspx

    Tx,

    Steve

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS6 compression links

  • Get your brand-new "Powered by IIS" button

    I was actually just surfing and ran across these.  Not real content worthy but they are cool!

    Powered By IIS 6 Powered By IIS 6 Powered By IIS 7
Powered By IIS 7

    Enjoy,

    Steve Schofield

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Time to learn Log Parser - book available

    I was doing some stuff with Log Parser over the weekend and wondered...Hmm is there a book available for Log Parser?  To my surprise there is one available. http://www.amazon.com/exec/obidos/ASIN/1932266526/larkware-20 has it available.  Bernard Cheah IIS MVP and http://www.IIS-Resources.com contributed to the book, so it must be good.  If you are not familiar with Bernard, he has been involved with IIS for years and answers questions all over the place, http://forums.iis.net, Microsoft newsgroups, www.iis-resources.com   I bought my copy and it is on the way!  Looks exciting, there is a sample chapter online at www.logparser.com how to query SNORT logs.  SNORT is an open source IDS (intrusion detection system) program.  www.snort.org is the link. 

    I even had a wild idea of integrating log parser into IISLogs (www.iislog.com) I developed and released a couple years back.  Hmm we'll see maybe a future version!  Stay tuned!

     

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • HTTP troubleshooting tools

    I've seen a few posts in the forums and newsgroup about various HTTP tools.  Here is a list I've seen so far. If you have one, feel free to add it to the post.  I saw a great post in the newsgroups but can't find it that had a few others..

    wfetch.exe
    http://support.microsoft.com/kb/284285

    Tinyget.exe
    http://support.microsoft.com/kb/840671

    Fiddler
    http://www.fiddlertool.com/fiddler/

    HTTPWatch
    http://www.httpwatch.com/

    IEWatch
    http://www.iewatch.com/

    Ethereal
    http://ethereal.com/

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Test connectivity with Telnet.

    Fellow co-worker blog about testing connectivity using Telnet.  This is a simple test to ensure your pc can talk remotely to a specific TCP port.

    http://blogs.orcsweb.com/carol/archive/2006/10/07/Telnet-Connection-Tests.aspx

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS7 - post #10 - Connecting to remote Longhorn server using WMI & root\WebAdministration namespace.

    I'm using a machine running Vista RC1 to query my remote Longhorn RC1 server.  The code samples listed below return information Worker Processes and helps recycle an application pool.  To recycle the app pool, I use Win32_Process class to start an AppCmd.exe.  One thing I found when connecting to a remote server is use the Management.AuthenticationLevel.PacketPrivacy enum.  This property allows you to connect otherwise you'll get Access Denied.   This property is part of the System.Management.ConnectionOptions namespace.

    'Here is a code sample
    Dim options As New System.Management.ConnectionOptions()
    options.Username = strUID
    options.Password = strPWD
    options.Impersonation = Management.ImpersonationLevel.Impersonate
    options.Authentication = Management.AuthenticationLevel.PacketPrivacy

    I tried using \root\WebAdministration to recycle app pools via WMI but I ran into an issue.  This is the error.

    "Access to the root\WebAdministration namespace was denied because the namespace is marked with RequiresEncryption but the script or application attempted to connect to this namespace with an authentication level below Pkt_Privacy. Change the authentication level to Pkt_Privacy and run the script or application again."

    Here is the thread http://forums.iis.net/thread/1421721.aspx, hopefully we'll have an answer.  Using the Win32_Process namespace to launch AppCmd.exe was a workaround.  I posted a couple other threads that are handy using WMI and the System.Management namespace to authenticate and connect to a remote server.  Check out my WMI tag.  Here are the code samples.

    Return Worker Process information.

       Sub Main()
            Whatever3("x.x.x.x", "lh5600\Administrator", "MyPassword")
       End Sub

       Function Whatever4(ByVal ServerName As String, ByVal strUID As String, ByVal strPWD As String) As String
            Try
                'Using System.Management to retrieve WMI / IIS7 info.
                'Define the WMI connection information
                Dim options As New System.Management.ConnectionOptions()
                options.Username = strUID
                options.Password = strPWD
                options.Impersonation = Management.ImpersonationLevel.Impersonate
                options.Authentication = Management.AuthenticationLevel.PacketPrivacy

                'Define the Scope information / Note the path defined.
                Dim scope As System.Management.ManagementScope
                scope = New System.Management.ManagementScope("\\" & ServerName & "\root\WebAdministration", options)

                'Define Query and Searcher objects
                Dim WMIQuery As New System.Management.SelectQuery("SELECT * FROM WorkerProcess")
                Dim searcher As New System.Management.ManagementObjectSearcher(scope, WMIQuery)

                'Connect to WMI
                Try
                    scope.Connect()
                Catch ex As Exception
                End Try

                'Write the list of Worker Process info 
                For Each queryObj As Management.ManagementObject In searcher.Get()

                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("WorkerProcess instance")
                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("ApplicationPool: {0}", queryObj("ApplicationPool"))
                Next

            Catch err As Management.ManagementException
                Console.WriteLine("An error occurred while querying for WMI data: " & err.Message)
            End Try
        End Function

    Recycle DefaultAppPool using AppCMD and WMI


        Sub Main()
            Whatever3("x,x,x,x", "lh5600\Administrator", "MyPassword!")
        End Sub

        Function Whatever3(ByVal ServerName As String, ByVal strUID As String, ByVal strPWD As String) As String
            Dim options As New System.Management.ConnectionOptions
            options.Username = strUID
            options.Password = strPWD
            options.Authentication = Management.AuthenticationLevel.PacketPrivacy

            Dim path As New System.Management.ManagementPath("\\" & ServerName & "\root\cimv2:Win32_Process")
            Dim scope As New System.Management.ManagementScope(path, options)

            scope.Connect()

            Dim opt As New System.Management.ObjectGetOptions()
            Dim classInstance As New System.Management.ManagementClass(scope, path, opt)

            Dim inParams As System.Management.ManagementBaseObject = classInstance.GetMethodParameters("Create")
            inParams("CommandLine") = "c:\windows\system32\inetsrv\appcmd recycle apppool defaultapppool"

            ' Execute the method and obtain the return values.
            Dim outParams As System.Management.ManagementBaseObject = classInstance.InvokeMethod("Create", inParams, Nothing)
            Return "ReturnValue:" & outParams("returnValue") & " Process ID: {0}" & outParams("processId")
        End Function

    Happy IIS7 coding!!

    Steve Schofield
    Microsoft MVP - IIS

     

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Send a Plain Text and HTML newsletter using System.Net.Mail namespace

    Send a Plain Text and HTML newsletter using System.Net.Mail namespace

     

    This article shows how to send an email that includes a Plain Text and HTML version.   The email client will display which version it is applicable.   The webpage uses System.Net.Mail built into .NET 2.0 to send the email. 

     

    Deployment and Testing

     

    ·        Create two files named Sendmail.aspx and Sendmail.aspx.vb

    ·        Deploy to your website.

    ·        Ensure the SMTP Service is installed on machine

    ·        Open sendmail.aspx in a browser and send a test message

    ·        Open your test message in an email client, this should display an HTML version.

    ·        Change your email client to only view message in Text format, the ‘text’ version should display.

     

    Sendmail.aspx webpage

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="sendmail.aspx.vb" ValidateRequest="false" 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>Send a Plain Text and HTML form</title>


    |</head>

    <body>

        <form id="form1" runat="server">

        <asp:Label ID="label1" runat="server"></asp:Label>

        <table border="1" width="505px">

            <tr>

                <td style='width: 7px'>

                    From</td>   

                <td>

                    <asp:TextBox ID="txtFrom" runat="server" Width="155px"></asp:TextBox></td>   

            </tr>

            <tr>

                <td style='width: 7px'>

                    To:</td>   

                <td>

                    <asp:TextBox ID="txtTo" runat="server" Width="157px"></asp:TextBox></td>   

            </tr>

            <tr>

                <td style='width: 7px; height: 23px'>

                    Subject</td>   

                <td style='height: 23px'>

                    <asp:TextBox ID="txtSubject" runat="server" Width="505px"></asp:TextBox></td>   

            </tr>   

            <tr>

                <td colspan="2">

                    TEXT Version Paste or type in text</td>   

            </tr>

             <tr>

                <td colspan="2">

                <asp:TextBox ID="txtText" TextMode="MultiLine" Columns="20" Rows="20" runat="server" Width="556px" Height="202px">


    This is the Text version


    </asp:TextBox>

                </td>

             </tr>         

             <tr>

                <td colspan="2">

                    HTML Version Paste or type in HTML formatted text</td>   

            </tr>

             <tr>

                <td colspan="2">

                <asp:TextBox ID="txtHTML" TextMode="MultiLine" Columns="20" Rows="20" runat="server" Width="559px" Height="249px">
    <html>

         <body>

         <h2>This is the HTML version</h2>

         </body>

    </body>
    </asp:TextBox>

                </td>

             </tr>

        </table>

            <asp:Button ID="Button1" runat="server" Text="Button" />

       

            </form>

    </body>

    </html>

     

    Sendmail.aspx.vb code behind

     

    Partial Class _Default

        Inherits System.Web.UI.Page

     

        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

            'Create the mail message

            Dim mail As New System.Net.Mail.MailMessage()

            mail.BodyEncoding = Encoding.GetEncoding("iso-8859-1")

     

            'Set the addresses

            mail.From = New System.Net.Mail.MailAddress(txtFrom.Text.ToString())

            mail.To.Add(txtTo.Text.ToString())

     

            'Set the content
            mail.Subject = txtSubject.Text.ToString()

     

            'Create the Plain Text part

            Dim plainView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(txtText.Text.ToString(), Nothing, "text/plain")

            plainView.TransferEncoding = Net.Mime.TransferEncoding.QuotedPrintable

     

            ‘Create the Html part

            Dim htmlView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(txtHTML.Text.ToString(), Nothing, "text/html")

            htmlView.TransferEncoding = Net.Mime.TransferEncoding.QuotedPrintable

     

            mail.AlternateViews.Add(plainView)

            mail.AlternateViews.Add(htmlView)

     

            'Send the message

            Dim smtp As New System.Net.Mail.SmtpClient("mail.iislogs.com") 'specify the mail server address

            smtp.Send(mail)

            label1.Text = "<b>Message Sent:" & System.DateTime.Now() & “</b>”

     

        End Sub 'MultiPartMime   

    End Class

     

    Reference Links

     

    ·        http://msdn2.microsoft.com/en-us/library/system.net.mail.aspx

    ·        http://www.systemnetmail.com

    ·        PINE Text based email client.  http://www.washington.edu/pine/getpine/

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Windows Server - IIS MVP award for 2007!

    Got the magic email I'm an IIS MVP for 2007!  Post your questions @ http://forums.iis.net or in the IIS Newsgroups

    -----------------------

    Dear Steve Schofield,

    Congratulations! We are pleased to present you with the 2007 Microsoft® MVP Award!
     
    The Microsoft MVP Award is our way of saying thank you and to honor and support the significant contributions you make to communities worldwide. As a recipient of Microsoft’s Most Valuable Professional award, you join an elite group of technical community leaders from around the world who foster the free and objective exchange of knowledge by actively sharing your real world expertise with users and Microsoft.  Microsoft salutes all MVPs for promoting the spirit of community and enhancing people’s lives and the industry’s success everyday.  To learn more about the MVP Program, visit: www.microsoft.com/mvp.

    Your extraordinary efforts in Windows Server - IIS technical communities during the past year are greatly appreciated. 

     -----------------------

    Share this post: Email it! | bookmark it! | digg it! | reddit!

Powered by Community Server 2.1