While operating with the IIS we all prefer to understand the settings done on the Virtual Directory are correct or not. therefore we are planning to see a way to do this programmatically. To check some properties of the IIS (Virtual Directory) of web based application after  install, one will create custom application for that. There are list of IIS Properties that we will get once post installation. The list of properties exposed by the IIS API or net Settings Property is mentioned below:

 

  • AuthFlags
  • Path
  • AppFriendlyName
  • EnableDirBrowsing
  • AccessRead
  • AccessExecute
  • AccessWrite
  • AccessScript
  • AuthNTLM
  • EnableDefaultDoc
  • DefaultDoc
  • AspEnableParentPaths

The top of settings are designed within the Metabase of the IIS.

IIS Metabase:
IIS Metabase may be a structure wherever IIS configuration settings are stored. You'll be able to navigate through the IIS Metabase using MetaEdit or Metabase explorer. The Metabase is predicated on a hierarchical  style with inheritance. Every object within the metabase has a KeyType. The KeyType property specifies the type of metabase key.
.NET provides the namespace that is used to induce the properties of the IIS Virtual Directory. .Net have the "System.DirectoryServices" namespace that exposes the DirectoryEntry class.

Code:
WebSettings.cs

public class WebSettings
{
     //Authentication Bitmask Values
     //Constant Value Description
     public const int MD_AUTH_ANONYMOUS = 0x00000001;
     //Anonymous authentication available.
     public const int MD_AUTH_BASIC = 0x00000002;
     //Basic authentication available.
     public const int MD_AUTH_NT = 0x00000004;

     //Windows authentication schemes available.
     string Auth_Type;
     public string calc(int AuthValue)
     {
         if (AuthValue == MD_AUTH_ANONYMOUS)
          {
               Auth_Type = "ANONYMOUS ACCESS ENABLED";
          }
          if (AuthValue == MD_AUTH_BASIC)
          {
               Auth_Type = "BASIC ACCESS ENABLED";
          }
          if (AuthValue == MD_AUTH_NT)
          {
               Auth_Type = "INTEGRATED WINDOWS ACCESS ENABLED";
         }
          if (AuthValue == (MD_AUTH_ANONYMOUS + MD_AUTH_NT))
          {
               Auth_Type = "INTEGRATED WINDOWS + ANONYMOUS ACCESS ENABLED";
          }
          if (AuthValue == (MD_AUTH_ANONYMOUS + MD_AUTH_BASIC))
         {
              Auth_Type="BASIC + ANONYMOUS";
         }
         if (AuthValue == (MD_AUTH_ANONYMOUS + MD_AUTH_NT))
         {
              Auth_Type = "INTEGRATED + ANONYMOUS";
         }
         if (AuthValue == (MD_AUTH_BASIC + MD_AUTH_NT))
         {
             Auth_Type = "BASIC + INTEGRATED";
        }
         if (AuthValue == (MD_AUTH_ANONYMOUS + MD_AUTH_BASIC + MD_AUTH_NT))
         {
             Auth_Type = "ANONYMOUS + BASIC + INTEGRATED";
         }
          return Auth_Type;
     }

Main.cs

string serverName;
string vDir;

serverName = System.Environment.MachineName;
vDir = "DirectoryName";
vdir = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/ROOT/" + vDir);
wbs = new WebSettings();
string[] sComp = new string[12];
sComp[0] = "AuthFlags";
sComp[1] = "Path";
sComp[2] = "AppFriendlyName";
sComp[3] ="EnableDirBrowsing";
sComp[4] ="AccessRead";
sComp[5] ="AccessExecute";
sComp[6] ="AccessWrite";
sComp[7] ="AccessScript";
sComp[8] ="AuthNTLM";
sComp[9] ="EnableDefaultDoc";
sComp[10] ="DefaultDoc";
sComp[11] ="AspEnableParentPaths";
ListViewItem[] listViewItem = new ListViewItem[12];
lstIISProperty.Items.Clear();
for (int i = 0; i < sComp.Length; i++)
{
    //lstComponents.MultiColumn = 2;
    lstIISProperty.Sorting = SortOrder.Ascending;
    if (sComp[i] != null)
    {
    listViewItem[i] = new ListViewItem(new string[]{ sComp[i], IISPropertyValue(sCompi]), fnExpected_Value(sComp[i])}, -1);
    lstIISProperty.Items.Add(listViewItem[i]);
    }
}