2
Я пытаюсь настроить мой IIS программно следующие шаги на этом msdn guideC#: пытаясь установить «ServerBindings» свойство моего сайта Programatically, продолжает врезаться
единственная разница я сделал был переход на WinForms вместо консоли .. и переменные вместо параметров функции.
однако код выдает исключение при попытке установить значение singleproperty ...
вот мой код ..
string metabasePath = "IIS://localhost/W3SVC/1234", propertyName = "ServerBindings";
object newValue = " :8080:";
try
{
DirectoryEntry path = new DirectoryEntry(metabasePath);
//when i try to retrieve the old value,it returns a null
PropertyValueCollection propValues = path.Properties[propertyName];
MessageBox.Show("7");
//the code throws an exception after messagebox,
//kinda old school debuging
path.Properties[propertyName][0] = newValue;
path.CommitChanges();
lblerror.Text = "Done";
}
catch (Exception ex)
{
if ("HRESULT 0x80005006" == ex.Message)
lblerror.Text = " Property does not exist at ";
else
lblerror.Text = "Failed in SetSingleProperty "+ ex.Message.ToString();
}