想通过DirectoryEntry和ManagementScope 来对IIS进行操作。
代码如下
public bool Connect()
{
if (_serverName == null)
return false;
try
{
_iisServer = new DirectoryEntry("IIS://" + _serverName + "/W3SVC/1");
_target = _serverName;
_connection = new ConnectionOptions();
_connection.Username = @"myname";
_connection.Password = "mypassword";
_scope = new ManagementScope(new ManagementPath(@"\\" + _serverName + @"\root\MicrosoftIISv2"), _connection);
_scope.Connect();
}
catch(Exception ex)
{
string msg = ex.Message;
return false;
}
return IsConnected();
}结果报如上错误。User credentials cannot be used for local connections
请指教!!多谢
代码如下
public bool Connect()
{
if (_serverName == null)
return false;
try
{
_iisServer = new DirectoryEntry("IIS://" + _serverName + "/W3SVC/1");
_target = _serverName;
_connection = new ConnectionOptions();
_connection.Username = @"myname";
_connection.Password = "mypassword";
_scope = new ManagementScope(new ManagementPath(@"\\" + _serverName + @"\root\MicrosoftIISv2"), _connection);
_scope.Connect();
}
catch(Exception ex)
{
string msg = ex.Message;
return false;
}
return IsConnected();
}结果报如上错误。User credentials cannot be used for local connections
请指教!!多谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货