IIS
  Home arrow IIS arrow Page 3 - Retrieving IIS information using ASP.NET 2...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
IIS

Retrieving IIS information using ASP.NET 2.0
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    2006-01-09

    Table of Contents:
  • Retrieving IIS information using ASP.NET 2.0
  • Retrieving basic IIS information using ASP.NET 2.0
  • Digging further for IIS information using ASP.NET 2.0
  • Can we learn more about the virtual directories (including web application information) present in IIS using ASP.NET 2.0?

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Retrieving IIS information using ASP.NET 2.0 - Digging further for IIS information using ASP.NET 2.0
    (Page 3 of 4 )

    The modified code, to have a bit more information, would be as follows:

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim dt As DataTable = getPropertyStruct()
                Dim dr As DataRow
                Dim searcher As New ManagementObjectSearcher("root\MicrosoftIISv2", "SELECT * FROM IIsWebService")
                For Each queryObj As ManagementObject In searcher.Get()
     
                    dr = dt.NewRow
                    dr("Name") = "Name"
                    dr("value") = queryObj("Name")
                    dt.Rows.Add(dr)
     
                    dr = dt.NewRow
                    dr("Name") = "DisplayName"
                    dr("value") = queryObj("DisplayName")
                    dt.Rows.Add(dr)
     
                    dr = dt.NewRow
                    dr("Name") = "PathName"
                    dr("value") = queryObj("PathName")
                    dt.Rows.Add(dr)
     
                    dr = dt.NewRow
                    dr("Name") = "Started"
                    dr("value") = queryObj("Started")
                    dt.Rows.Add(dr)
     
     
                    dr = dt.NewRow
                    dr("Name") = "State"
                    dr("value") = queryObj("State")
                    dt.Rows.Add(dr)
     
                    dr = dt.NewRow
                    dr("Name") = "Status"
                    dr("value") = queryObj("Status")
                    dt.Rows.Add(dr)
     
                    dr = dt.NewRow
                    dr("Name") = "SystemName"
                    dr("value") = queryObj("SystemName")
                    dt.Rows.Add(dr)
     
                Next
                Me.GridView1.DataSource = dt
                Me.GridView1.DataBind()
            Catch err As ManagementException
                Response.Write(err.Message)
            End Try
        End Sub

    This time, instead of working with the “IIsWebInfo” class, I shifted to another class, “IIsWebService,” which gives you much more information than the previous class.

    Retrieving all virtual directories present in IIS using ASP.NET 2.0

    This is a bit different from the above coding style.  First of all, let us look at the program.

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim dt As DataTable = getVirtualRootStruct()
                Dim dr As DataRow
                Dim searcher As New ManagementObjectSearcher("root\MicrosoftIISv2", "SELECT * FROM IIsWebVirtualDir")
                For Each queryObj As ManagementObject In searcher.Get()
                    dr = dt.NewRow
                    dr("AppRoot") = queryObj("AppRoot")
                    dr("Caption") = queryObj("Caption")
                    dr("Description") = queryObj("Description")
                    dr("Name") = queryObj("Name")
                    dr("Status") = queryObj("Status")
                    dt.Rows.Add(dr)
                Next
                Me.GridView1.DataSource = dt
                Me.GridView1.DataBind()
            Catch err As ManagementException
                Response.Write(err.Message)
            End Try
        End Sub

    To get the virtual directory information, we need to work with the class “IIsWebVirtualDir”.  It has got a lot of properties.  I just selected only the most important ones.  I am using another routine to form a structure, to store that property information.  The routine is as follows.

    Private Function getVirtualRootStruct() As DataTable
            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn("AppRoot"))
            dt.Columns.Add(New DataColumn("Caption"))
            dt.Columns.Add(New DataColumn("Description"))
            dt.Columns.Add(New DataColumn("Name"))
            dt.Columns.Add(New DataColumn("Status"))
            Return dt
        End Function

    All the columns are indirectly nothing but the properties, and the rest is the same as I explained in the first section.

    More IIS Articles
    More By Jagadish Chaterjee


       · [i]This article explains how to retrieve “basic IIS” information using ASP.NET...
       · The correct code download link...
       · I am getting 'invalid namespace" error when i am trying to execute the given...
       · I am getting 'invalid namespace" error when i am trying to execute the given...
       · You need to refer/import all of the following namespaces before you proceed...
       · In the default.aspx.vb I get the errorProvider Load Failuer on the next that goes...
     

    IIS ARTICLES

    - Retrieving IIS information using ASP.NET 2.0
    - IIS 6.0, Getting Information Using WMI
    - The Importance of a Domain
    - Implementing a PKI, Part II: Configuring IIS...
    - Creating Test and Production Sites with Only...
    - Authentication and Authorization
    - Beefing Up IIS: 10 Tips From A Former Solari...
    - An Introduction To ISAPI
    - Secure Your Web Server With SSL
    - Introduction to HTML and ASP
    - Instructions to help in Designing your own C...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway