host headers c# add programmatically

G

greg

we need to add host headers to a IIS site (not default one)

in .NET/c#

we can print host headers but cannot insert programmatically new one



bellow is our code

DirectoryEntry TemplSite = new DirectoryEntry("IIS://LocalHost/w3svc/6");

if (TemplSite.SchemaClassName == "IIsWebServer")

{

Console.WriteLine(TemplSite.Name);

Console.WriteLine(TemplSite.Properties["ServerComment"].Value.ToString());

object[] hosts = (object[])TemplSite.Properties["ServerBindings"].Value;


foreach(string host in hosts)

{

Console.WriteLine(host);

}


///// DOES NOT WORK

ArrayList hostsList = new ArrayList(hosts);

hostsList.Add(":80:qqqqqq2.com");

object[] newhosts = hostsList.ToArray();


TemplSite.Properties["ServerBindings"].Value = (object)newhosts;


}

Thanks

GSL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top