IIS
  Home arrow IIS arrow Page 4 - 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

    Free Web 2.0 Code Generator! Generate data entry 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 - Can we learn more about the virtual directories (including web application information) present in IIS using ASP.NET 2.0?
    (Page 4 of 4 )

    We can dig still further, but with a different class, as shown in the following program.

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim dt As DataTable = getStruct()
                Dim dr As DataRow
                Dim searcher As New ManagementObjectSearcher("root\MicrosoftIISv2", "SELECT * FROM IIsWebVirtualDirSetting")
                For Each queryObj As ManagementObject In searcher.Get()
                    dr = dt.NewRow
                    dr("AppPoolId") = queryObj("AppPoolId")
                    dr("Name") = queryObj("Name")
                    dr("Path") = queryObj("Path")
                    dr("EnableDirBrowsing") = queryObj("EnableDirBrowsing")
                    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 further in-depth information about the virtual directories, we need to work with the class “IIsWebVirtualDirSettng.”  It also has a lot of properties.  I 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 getStruct() As DataTable
            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn("Name"))
            dt.Columns.Add(New DataColumn("Path"))
            dt.Columns.Add(New DataColumn("AppPoolId"))
            dt.Columns.Add(New DataColumn("EnableDirBrowsing"))
            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.

    How about retrieving SMTP, FTP, POP3 information using ASP.NET 2.0?

    We can even retrieve that information as well.  But we need to switch back again to the first style.  Let us proceed with the following code.

    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 IIsSmtpService")
                For Each queryObj As ManagementObject In searcher.Get()
     
                    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") = "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

    To retrieve information about SMTP, we need to work with the class “IIsSmtpService.”  Similarly, to work with FTP, we need to work with “IIsFtpService,” and so on.

    Any comments, suggestions, ideas, improvements, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · [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 4 hosted by Hostway