The IIS Metabase is XML representation of the IIS instance, it's actually an XML file stored in IIS. It can be access using apps like MetaEdit or programmatically using the Active Directory through a class System.DirectoryServices.DirectoryEntry.
using System.Collections.Generic;
using System.Text;
using System;
using System.Data;
using System.Configuration;
using System.DirectoryServices;
using System.Web.Configuration;
namespace IISMetabase
{
class IISMetabase
{
private string _machineName = "localhost";
private System.Collections.IDictionary _applications;//collection of websites
private Configuration _config;
public IISMetabase()
{
_applications = new System.Collections.Hashtable();
}
public System.Collections.IDictionary GetApplications()
{
DirectoryEntry webentry = new DirectoryEntry();
String path = "IIS://" + _machineName + "/W3SVC/1/ROOT";
webentry.Path = path;
Boolean exists = false;
try
{
exists = DirectoryEntry.Exists(path);
}
catch (System.Runtime.InteropServices.COMException e)
{
String error = e.Message;
Console.WriteLine(error + "\n");
}
if (exists)
{
DirectoryEntries webSiteChildren = webentry.Children;
foreach (DirectoryEntry website in webSiteChildren)
{
String scn = website.SchemaClassName;
String se = website.SchemaEntry.ToString();
if (website.Properties.Contains("KeyType"))
{
String webName = website.Name;
try
{
Object keyTypeValue = website.InvokeGet("KeyType");
String keyTypeValueStr = keyTypeValue.ToString();
if (!keyTypeValueStr.Equals(""))
{
try
{
_config = WebConfigurationManager.OpenWebConfiguration("/" + webName);
_applications.Add(webName, _config);
}
catch (ConfigurationErrorsException err)
{
String error = err.Message;
Console.WriteLine(error + "\n");
}
}
}
catch (Exception err)
{
Console.WriteLine(err.Message + "\n");
continue;
}
}
}
}
else
{
String err = "The Directory " + webentry.Path + "does not exist\n";
Console.WriteLine(err + "\n");
}
return _applications;
}
}
}
Friday, January 9, 2009
How to access the IIS Metabase programmatically, IIS metabase
Labels:
IIS,
IIS Metabase,
Metabase,
Security,
Web.config
Subscribe to:
Posts (Atom)
Archives
-
►
2008
(527)
-
►
October
(20)
- Extend BoundField Of GridView
- How To Add Tooltip in GridView
- Building a Simple CSV Parser in C#
- C# Tutorial - Extension Methods
- C# Tutorial - The Readonly Keyword
- How To - Prevent Script Attacks
- How To: Prevent Cross-Site Scripting in ASP.NET
- How To Add Title Attribute To GridView Row
- Hidden Field Inside GridView
- How To Display data in marquee from database by us...
- FileUpload and Ajax UpdatePanel
- Binding Data to a Web Forms DataList
- How To Open div popup with a LightBox effect
- Asynchronous GridView in 5 simple steps
- size of the viewstate in ASP.NET
- How To Create a Value Type That Can Be Initialized...
- How To Add Programming Languages in the App_Code F...
- How To Create A Filebrowser in ASP
- How to add an RSS feed to your website
- Export Html to Pdf using iTextSharp(GridView)
-
►
September
(257)
- How to display a serial number from 1 to n in a gr...
- Load Controls Dynamically in ASP.NET
- Three Tier Architecture with ASP.NET
- ADO.NET Tutorial
- Building a DAL using Strongly Typed TableAdapters ...
- Return new identity from Strongly Typed Dataset Da...
- Select a row in an asp:GridView without using a Se...
- How To Restrict the number of rows in a dataview w...
- How To Convert HTML to Text, Easily
- How To Post Data From ASP.net To Another URL
- The .NET Replacement for App.Path
- Binding a Listcontrol(Dropdownlist) to Enumeration...
- Tips
- using arrayList as DataSource for Gridview
- Enum With String Values In C#
- Making a small Popup picture on mouse over event
- Databinding Tips: Nesting Eval Statements
- How To Add Checkboxlist Dynamically
- Working with the DOM
- Performing a Server Request Asynchronously
- Autosugget Using xmlHTTP in Asp.net
- Asynchronous Request to Server (JavaScript)
- How To Create Ajax Based Search Page using xmlHTTP...
- How To Create Ajax Based Search Page using xmlHTTP...
- How TO Use XMLHTTP Object in C#
-
►
October
(20)



