IIS
  Home arrow IIS arrow Page 2 - Retrieving IIS information using ASP.NET 2...
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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 / 42
    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
     
     
    ADVERTISEMENT


    Retrieving IIS information using ASP.NET 2.0 - Retrieving basic IIS information using ASP.NET 2.0


    (Page 2 of 4 )

    The following program helps you to retrieve basic IIS information.

    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 IIsWebInfo")
                For Each queryObj As ManagementObject In searcher.Get()
     
                    dr = dt.NewRow
                    dr("Name") = "Caption"
                    dr("value") = queryObj("Caption")
                    dt.Rows.Add(dr)
     
                    dr = dt.NewRow
                    dr("Name") = "Description"
                    dr("value") = queryObj("Description")
                    dt.Rows.Add(dr)
     
                    dr = dt.NewRow
                    dr("Name") = "InstallDate"
                    dr("value") = queryObj("InstallDate")
                    dt.Rows.Add(dr)
     
                    dr = dt.NewRow
                    dr("Name") = "MajorIIsVersionNumber"
                    dr("value") = queryObj("MajorIIsVersionNumber")
                    dt.Rows.Add(dr)
     
     
                    dr = dt.NewRow
                    dr("Name") = "MinorIIsVersionNumber"
                    dr("value") = queryObj("MinorIIsVersionNumber")
                    dt.Rows.Add(dr)
     
                    dr = dt.NewRow
                    dr("Name") = "Name"
                    dr("value") = queryObj("Name")
                    dt.Rows.Add(dr)
     
                    dr = dt.NewRow
                    dr("Name") = "Status"
                    dr("value") = 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

    Details about the program

    Even though the above program is a bit lengthy, it is very simple to understand.  In the above program I am using “getPropertyStruct,” which is used to create and return a data table which can hold any number of “key,value” pairs.  You can also work with “collections” instead of working with the “data table.”  “getPropertyStruct” is defined as follows:

    Private Function getPropertyStruct() As DataTable
            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn("Name"))
            dt.Columns.Add(New DataColumn("Value"))
            Return dt
        End Function

    The main statements within the above program (in the previous section) are as follows:

                Dim searcher As New ManagementObjectSearcher("root\MicrosoftIISv2", "SELECT * FROM IIsWebInfo")
                For Each queryObj As ManagementObject In searcher.Get()

    The first statement connects to the “root\MicrosoftIISv2” namespace. We are trying to issue a SELECT statement based on a built-in class, “IIsWebInfo.”  It would return all the objects associated with the class “IIsWebInfo” and I handle them (each) with “queryObj” which is of type “ManagementObject.”

    With every object I receive from “queryObj,” I extract the information into a new “data row” which would finally be added to the “data table” (as follows).

                    dr = dt.NewRow
                    dr("Name") = "Name"
                    dr("value") = queryObj("Name")
                    dt.Rows.Add(dr)

    Finally, I assign the data table information to the grid by issuing the following statements:

                Me.GridView1.DataSource = dt
                Me.GridView1.DataBind()

    The next section further digs out the IIS information.

    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...
       · I'm getting 'invalid namespace' error. included all the references. seems to be a...
     

    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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT