Here is an example code snippet for changing an existing http binding port 80 on the default website to port 90:
int iisNumber = 1; // Default Website is IIS#1 using(ServerManager serverManager = new ServerManager()) { Site site = serverManager.Sites.FirstOrDefault(s => s.Id == iisNumber); if(site != null) { Binding binding = site.Bindings .Where(b => b.BindingInformation == "*:80:" && b.Protocol == "http") .FirstOrDefault(); binding.BindingInformation = "*:90:"; serverManager.CommitChanges(); Console.WriteLine(""); } }
Field
A BindingInformation is a string consisting of:
<ip address>:<port>:<host header>
For instance:
*:80: - listening on all IP addresses, port 80, no host header*:90:example.com - listen on all IP addresses, port 80, but respond if the host header matches example.com172.16.3.1:80:example.com - listening on the IP address 172.16.3.1, port 80, and if the host header is example.com
source share