Application Extension Mapping can be programmatically added using "DirectoryEntry" class in "System.DirectoryServices" namespace.
using System.DirectoryServices;
public class DirEntry
{
public void SetSingleProperty(string metabasePath, string propertyName, object newValue)
{
// metabasePath is of the form "IIS://servername/path"
try
{
DirectoryEntry path = new DirectoryEntry(metabasePath);
PropertyValueCollection propValues = path.Properties[propertyName];
string oldValue = propValues.Value;
path.Properties[propertyName][0] = newValue;
path.CommitChanges();
Console.WriteLine("Done");
}
catch (Exception ex)
{
if ("HRESULT 0x80005006" == ex.Message)
Console.WriteLine(" Property {0} does not exist at {1}",
propertyName, metabasePath);
else
Console.WriteLine("Failed in SetSingleProperty with the
following exception: \n{0}", ex.Message);
}
}
}
"SetSingleProperty" method can be used to add any DirectoryEntry.
For adding IIS Application Extension Mapping "ScriptMaps" Property to be added.
i.e
DirEntry de = new DirEntry();
de.SetSingleProperty("IIS://localhost/W3SVC/1/ROOT", "ScriptMaps",
@".htm,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET, HEAD, POST");