Get IIS bindings at runtime Get IIS bindings at runtime asp.net asp.net

Get IIS bindings at runtime


The only way to achieve that (without being an administrator) is using Microsoft.Web.Administration. I just wrote a quick blog on how to do that, see:
http://blogs.msdn.com/b/carlosag/archive/2011/01/21/get-iis-bindings-at-runtime-without-being-an-administrator.aspx

Basically since IIS has a feature we call Worker Process isolation it is possible to read the configuration from an Application itself without the need of being administrator. If you use ADSI, Metabase, or any other way, you will require being an administrator.


You should be able to accomplish this by accessing the IIS metabase, using the System.DirectoryServices assembly.

For example, here you can enumerate through all of your sites and property configurations contained within those sites.

Add this reference to your project:

using System.DirectoryServices

// Assuming your Server Id is 1, and you are connecting to your local IIS.DirectoryEntry de = new DirectoryEntry(@"IIS://localhost/W3SVC/1/Root");foreach (DirectoryEntry entry in de.Children){   foreach (PropertyValueCollection property in entry.Properties)   {      Console.WriteLine("Name: {0}, Value {1}",property.PropertyName, property.Value);   }}