MOHAMED JACKARIAH

MOHAMED JACKARIAH

  • 1.6k
  • 181
  • 33.4k

How Programmatically Validate IIS Website IP and Port number

Mar 16 2015 5:13 AM
Hi,
I have written following code for validate the exiting website binding information. But, I could not get the result. Its validate the IIS express sites only. what can I do for validate the IIS Website programmatically.
my code is
 bool bind=true;
using (ServerManager manager = new ServerManager())
{
SiteCollection sites = manager.Sites;
foreach (var IISsite in sites)
{
BindingCollection bindings = IISsite.Bindings;
foreach (Microsoft.Web.Administration.Binding binding in bindings)
{
var oo = IISsite.Bindings
.Where(b => b.EndPoint != null
&& b.EndPoint.Address.ToString() == Bindings
&& b.EndPoint.Port == portNumber)
.FirstOrDefault();
if (oo != null)
return false;
}
}
}
return bind;